以习惯性 Go 语言编写的 Windows API 和 GUI。
Win32 API and GUI in idiomatic Go.
Handwritten since 2019.
Windigo is designed to be familiar to C/C++ Win32 programmers, using the same concepts, and an API as close as possible to the original Win32 API. This allows most C/C++ Win32 tutorials and examples to be translated to Go.
Notably, Windigo is written 100% in pure Go – CGo is not used, just native syscalls.
Windigo is based in Go 1.20, so it can be built in Windows 7 and above.
go get -u github.com/rodrigocfd/windigoNative FFI items currently implemented:
| Native FFI item | Count |
|---|---|
| Handles | 32 |
| Structs | 212 |
| Functions | 706 |
| COM interfaces | 84 |
| COM methods | 560 |
| Const types | 443 |
| Const values | 11,303 |
In the examples below, error checking is ommited for brevity.
GUI window
The example below creates a window programmatically, and handles the button click. Also, it uses the minimal.syso provided in the _resources folder.
…To compile the final .exe file, run the command:
go build -trimpath -ldflags "-s -w -H=windowsgui"Registry access
…Enumerating running processes
The example below takes a process snapshot to list the running processes:
package main
import (
"github.com/rodrigocfd/windigo/co"
"github.com/rodrigocfd/windigo/win"
)
func main() {
hSnap, _ := win.CreateToolhelp32Snapshot(co.TH32CS_SNAPPROCESS, 0)
defer hSnap.CloseHandle()
processes, _ := hSnap.EnumProcesses()
for _, nfo := range processes {
println("PID:", nfo.Th32ProcessID, "name:", nfo.SzExeFile())
}
println(len(processes), "found")
}Taking a screenshot
This complex example takes a screenshot using GDI and saves it to a BMP file.
…Component Object Model (COM)
Windigo has full support for C++ COM objects. The cleanup is performed by a win.OleReleaser object, which calls Release on multiple COM objects at once, much like an arena allocator. Every function which produces a COM object requires a win.OleReleaser to take care of its lifetime.
The example below uses COM objects to display the system native Open File window:
…COM Automation
Windigo has bindings to IDispatch COM interface and VARIANT parameters, allowing you to invoke Automation methods.
The example below manipulates an Excel spreadsheet, saving a copy of it:
…The library is divided in several packages. Core packages are located at at the root of the library, extended packages under x/ subdirectory.
| Entities | Consts | Description |
|---|---|---|
ui |
– | Core high-level UI windows and controls |
wstr |
– | Core string and UTF-16 wide string management |
win |
co |
Core Win32 components |
winaut |
coaut |
Automation |
windxgi |
codxgi |
DirectX Graphics Infrastructure |
winsh |
cosh |
Windows Shell |
wintasks |
cotasks |
Task Scheduler |
winwic |
cowic |
Windows Imaging Component |
Core packages dependency:
flowchart BT
internal/utl([internal/utl]) --> co
ui --> win
win --> internal/dll([internal/dll])
win --> internal/utl
win --> wstrLicensed under MIT license, see LICENSE.md for details.
暂无开放 Issues,或尚未同步最近议题。