go walk 初识

go walk是go的windows gui库,但是网上资料较少,浪费了点时间,因此进行记录

go walk折腾了小半天,终于在win10下成功运行了,下面是步骤

写main.go:

func main() {
	var inTE, outTE *walk.TextEdit

	if _, err := (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(); err != nil {
		log.Fatal(err)
	}
}

此时目录如下:

ProjectDir
│  main.go

之后在目录下加入project.exe.manifest,这个名字随便起了,内容为:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
	<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>
	<asmv3:application>
		<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
			<dpiAware>true</dpiAware>
		</asmv3:windowsSettings>
	</asmv3:application>
</assembly>

此时目录结构:

ProjectDir
│  main.go
│  project.exe.manifest

之后安装rsrc tool,安装这个作用是将上面的project.exe.manifest生成rsrc.syso,命令为rsrc -manifest project.exe.manifest -o rsrc.syso

到这里就可以进行正常的build操作了,注意的是这里不能直接用go run运行,会报错TTM_ADDTOOL failed,虽然还不太清楚原理,应该是没有把上面的rsrc.syso编译进去导致的

编译使用go build或者go build -ldflags="-H windowsgui",后者运行时只会显示程序本身,前者会多个CMD运行框

PS:最后安利个项目 https://blog.csdn.net/bw761813/article/details/89673030 用walk实现的博客查询器 😋

posted @ 2021-01-28 14:37  seas  阅读(2372)  评论(0编辑  收藏  举报