walk是windows上的gui库,不能跨平台,只在windows上。
walk 的项目地址: https://github.com/lxn/walk
文档地址:https://godoc.org/github.com/lxn/walk
其内容是固定的。
go build main.go
或者,此法在工程文件夹内运行,且不再依赖个cmd,如下:
go build -ldflags="-H windowsgui"
窗体显示例子
package main import ( "github.com/lxn/win" "github.com/lxn/walk" . "github.com/lxn/walk/declarative" ) const ( SIZE_W = 600 SIZE_H = 400 ) type MyMainWindow struct { *walk.MainWindow } func main() { mw := new(MyMainWindow) MainWindow{ Visible: false, AssignTo: &mw.MainWindow, }.Create() win.SetWindowLong(mw.Handle(), win.GWL_STYLE, win.WS_BORDER) // removes default styling xScreen := win.GetSystemMetrics(win.SM_CXSCREEN) yScreen := win.GetSystemMetrics(win.SM_CYSCREEN) win.SetWindowPos( mw.Handle(), 0, (xScreen - SIZE_W)/2, (yScreen - SIZE_H)/2, SIZE_W, SIZE_H, win.SWP_FRAMECHANGED, ) win.ShowWindow(mw.Handle(), win.SW_SHOW) mw.Run() }