golang 如何开发windows窗口界面
go get github.com/lxn/walk
package main
import (
"log"
"strings"
"github.com/lxn/walk"
."github.com/lxn/walk/declarative"
)
func init(){
log.SetFlags(log.Ldate|log.Lshortfile)
}
func main(){
var inTE,outTE *walk.TextEdit
MainWindow{
Title: "test",
MinSize: Size{600,400},
Layout: VBox{},
Children: []Widget{
HSplitter{
Children:[]Widget{
TextEdit{AssignTo:&inTE,MaxLength:10},
TextEdit{AssignTo:&outTE,ReadOnly:true},
},
},
PushButton{
Text: "SCREAM",
OnClicked: func(){
outTE.SetText(strings.ToUpper(inTE.Text()))
},
},
},
}.Run()
}
go get github.com/akavel/rsrc
拉取下来之后,就会在GOPATH/src/bin中会发现有一个rsrc.exe
- 在上面例子的同文件下,创建一个gui.mainifest的文件,并且在里面写入:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
</assembly>
rsrc -manifest gui.manifest -o rsrc.syso
go build -ldflags="-H windowsgui"
- 点击运行gui.exe即可
- 文件结构为
golang 如何开发windows窗口界面