https://github.com/rodrigocfd/windigo
Windows API and GUI in idiomatic Go.
https://github.com/rodrigocfd/windigo
ffi go golang gui native win32 windows
Last synced: about 1 month ago
JSON representation
Windows API and GUI in idiomatic Go.
- Host: GitHub
- URL: https://github.com/rodrigocfd/windigo
- Owner: rodrigocfd
- License: mit
- Created: 2021-02-18T10:46:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-05-13T20:19:57.000Z (about 1 month ago)
- Last Synced: 2025-05-13T21:33:05.679Z (about 1 month ago)
- Topics: ffi, go, golang, gui, native, win32, windows
- Language: Go
- Homepage: https://pkg.go.dev/github.com/rodrigocfd/windigo
- Size: 2.74 MB
- Stars: 458
- Watchers: 12
- Forks: 27
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/rodrigocfd/[email protected])
[](https://github.com/rodrigocfd/windigo)
[](https://github.com/rodrigocfd/windigo)
[](https://github.com/rodrigocfd/windigo/blob/master/LICENSE.md)# Windigo
Win32 API and GUI in idiomatic Go.
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.
## Example
The example below creates a window programmatically, and handles the button click. Also, it uses the `minimal.syso` provided in the [resources](resources/) folder.

```go
package mainimport (
"fmt"
"runtime""github.com/rodrigocfd/windigo/ui"
"github.com/rodrigocfd/windigo/win/co"
)func main() {
runtime.LockOSThread()myWindow := NewMyWindow() // instantiate
myWindow.wnd.RunAsMain() // ...and run
}// This struct represents our main window.
type MyWindow struct {
wnd *ui.Main
lblName *ui.Static
txtName *ui.Edit
btnShow *ui.Button
}// Creates a new instance of our main window.
func NewMyWindow() *MyWindow {
wnd := ui.NewMain( // create the main window
ui.OptsMain().
Title("Hello you").
Size(ui.Dpi(340, 80)).
ClassIconId(101), // ID of icon resource, see resources folder
)lblName := ui.NewStatic( // create the child controls
wnd,
ui.OptsStatic().
Text("Your name").
Position(ui.Dpi(10, 22)),
)
txtName := ui.NewEdit(
wnd,
ui.OptsEdit().
Position(ui.Dpi(80, 20)).
Width(ui.DpiX(150)),
)
btnShow := ui.NewButton(
wnd,
ui.OptsButton().
Text("&Show").
Position(ui.Dpi(240, 19)),
)me := &MyWindow{wnd, lblName, txtName, btnShow}
me.events()
return me
}func (me *MyWindow) events() {
me.btnShow.On().BnClicked(func() {
msg := fmt.Sprintf("Hello, %s!", me.txtName.Text())
me.wnd.Hwnd().MessageBox(msg, "Saying hello", co.MB_ICONINFORMATION)
})
}
```To release the `.exe` file, run the command:
```
go build -ldflags "-s -w -H=windowsgui"
```## Architecture
The library is divided in two main packages:
* `ui` – high-level windows and controls;
* `win` – low-level native Win32 bindings.More specifically:
| Package | Description |
| - | - |
| `ui` | High-level UI windows and controls. |
| `win` | Native Win32 structs, handles and functions. |
| `win/co` | Native Win32 constants, all typed. |
| `win/ole` | COM bindings. |
| `win/ole/oleaut` | COM automation bindings. |
| `win/ole/shell` | Shell COM bindings. |
| `win/wstr` | String and UTF-16 wide string management. |Internal package dependency:
```mermaid
flowchart BT
internal/utl([internal/utl]) --> win/co
ui --> win
win --> internal/dll([internal/dll])
win --> internal/utl
win --> win/wstr
win/ole --> win
win/ole/oleaut --> win/ole
win/ole/shell --> win/ole
```## Legacy version
As of May 2025, Windigo was heavily refactored, featuring:
* simpler package organization;
* more strict error handling;
* more performant [UTF-16](https://learn.microsoft.com/en-us/windows/win32/learnwin32/working-with-strings) string conversion, with short string optimization;
* a new [COM](https://en.wikipedia.org/wiki/Component_Object_Model) implementation.If, for some reason, you can't upgrade right now, just point your go.mod to the old version:
```
go get github.com/rodrigocfd/[email protected]
```## License
Licensed under [MIT license](https://opensource.org/licenses/MIT), see [LICENSE.md](LICENSE.md) for details.