A Go GUI framework on the Windows platform.
package main
import (
"github.com/mkch/gw/app"
"github.com/mkch/gw/button"
"github.com/mkch/gw/win32"
"github.com/mkch/gw/win32/win32util"
"github.com/mkch/gw/window"
)
func main() {
win, _ := window.New(&window.Spec{
Text: "Hello, Go!",
Style: win32.WS_OVERLAPPEDWINDOW,
X: win32.CW_USEDEFAULT,
Width: 500, Height: 300,
OnClose: func() { app.Quit(0) },
})
button.New(win.HWND(), &button.Spec{
Text: "Hello",
Style: win32.WS_VISIBLE,
X: 200, Y: 120,
Width: 100, Height: 60,
OnClick: func() {
win32util.MessageBox(win.HWND(),
"Hello GUI!", "Button clicked",
win32.MB_ICONINFORMATION)
},
})
win.Show(win32.SW_SHOW)
app.Run()
}The Go program above creates a window and a button. When the button is clicked, a message box pops up.
-
How to remove the console window when the executable is run?
Add
-ldflags "-H=windowsgui"when runninggo build, for example:go build -ldflags "-H=windowsgui". -
How to specify an icon or other resources for the executable?
You can use a third-party tool, such as
rsrc.First, use the command
go get github.com/akavel/rsrcto install rsrc.Then use a command such as
rsrc -arch amd64 -ico FILE.icoto compile the *.ico file into *.syso resource file.Finally, place the *.syso file in the same directory as the *.go source files, and then run go build.