环境信息
win10专业版
vscode1.71.2
go1.19
1.安装walk
https://github.com/lxn/walk
go get github.com/lxn/walk
2.安装rsrc
Then either compile the manifest using the rsrc tool
go get github.com/akavel/rsrc
进入目录 %GOPATH%\pkg\mod\github.com\akavel\rsrc@v0.10.2
go build 生成 rsrc.exe文件
3.配置rsrc环境变量
配置环境变量 win+r 启动运行 输入 sysdm.cpl 在PATH增加rsrc的路径
注意:如果使用的vscode那么需要重启后环境变量才会生效
4.create test.go
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"strings"
)
func main() {
var inTE, outTE *walk.TextEdit
MainWindow{
Title: "SCREAMO",
MinSize: Size{600, 400},
Layout: VBox{},
Children: []Widget{
HSplitter{
Children: []Widget{
TextEdit{AssignTo: &inTE},
TextEdit{AssignTo: &outTE, ReadOnly: true},
},
},
PushButton{
Text: "SCREAM",
OnClicked: func() {
outTE.SetText(strings.ToUpper(inTE.Text()))
},
},
},
}.Run()
}
4.Create Manifest test.manifest
<?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>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
</windowsSettings>
</application>
</assembly>
4.编译manifest 文件(注意test.go和test.manifest两个文件都放到一个目录执行下面命令)
rsrc -manifest test.manifest -o rsrc.syso
可以添加exe图标
rsrc -manifest test.manifest -ico test.ico -o rsrc.syso
5.Build app(第一种有控制台窗口可查看日志,第二种无控制台窗口,适用程序最后打包使用)
In the directory containing test.go run
go build
To get rid of the cmd window, instead run
go build -ldflags="-H windowsgui"
6.Run app
test.exe
Sample Output (Windows 10)