Skip to content

mkch/gw

Repository files navigation

gw

简体中文

A Go GUI framework on the Windows platform.

Usage

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.

FAQ

  1. How to remove the console window when the executable is run?

    Add -ldflags "-H=windowsgui" when running go build, for example: go build -ldflags "-H=windowsgui".

  2. 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/rsrc to install rsrc.

    Then use a command such as rsrc -arch amd64 -ico FILE.ico to 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.

About

gw is a golang GUI for windows.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages