Go语言 如何使用Gio设置标题栏图标

5jdjgkvh  于 2023-11-14  发布在  Go
关注(0)|答案(1)|浏览(304)

Gio UI(https://gioui.org/)有问题。


的数据
正如你看到的,窗口图标没有设置,也没有设置它的选项。
创建新窗口时,只能设置标题:

  1. w := app.NewWindow(app.Title("My APP Title"))

字符串
但是如果我理解正确的话,图标应该从资源清单中加载:

  1. go\pkg\mod\[email protected]\app\internal\windows\windows.go


//

  1. func LoadImage(hInst syscall.Handle, res uint32, typ uint32, cx, cy int, fuload uint32) (syscall.Handle, error) {
  2. h, _, err := _LoadImage.Call(uintptr(hInst), uintptr(res), uintptr(typ), uintptr(cx), uintptr(cy), uintptr(fuload))
  3. if h == 0 {
  4. return 0, fmt.Errorf("LoadImageW failed: %v", err)
  5. }
  6. return syscall.Handle(h), nil
  7. }


要构建资源清单,我使用go winres:https://github.com/tc-hib/go-winres
我已经在winres.json中正确设置了应用程序图标和指南中解释的图标。
我认为应该有一种方法来设置应用程序标题中的窗口图标,但我找不到我应该在json中指定哪个键:

  1. {
  2. "RT_GROUP_ICON": {
  3. "APP": {
  4. "0000": [
  5. "icon_64.png",
  6. "icon_48.png",
  7. "icon_32.png",
  8. "icon_16.png"
  9. ]
  10. },
  11. "OTHER": {
  12. "0000": "icon.png"
  13. },
  14. "#42": {
  15. "0409": "icon_EN.ico",
  16. "040C": "icon_FR.ico"
  17. }
  18. }
  19. }

nkhmeac6

nkhmeac61#

官方的方法是使用gogio工具,不幸的是,它的文档非常糟糕,与go-winres相比有很多限制。
使用go install gioui.org/cmd/gogio@latest安装
然后使用以下命令编译应用程序:

  1. @GOOS=windows GOARCH=amd64 gogio -buildmode=exe -icon=appicon.png -arch=amd64 -target=windows -o myapp.exe app-path/

字符串
根据您的需求更改架构和路径。
无论如何,据我所知,gogio只支持png,它会自动生成所有需要的决议。
由于我想使用go-winres,我刚刚使用Resource Hacker来反编译exe资源。
我发现要设置图标,你需要像这样设置winres.json:

  1. {
  2. "RT_GROUP_ICON": {
  3. "#1": {
  4. "0409": "myicon_EN.ico"
  5. }
  6. },
  7. "RT_MANIFEST": {
  8. "#1": {
  9. "0409":
  10. // Your settings
  11. }
  12. }


然后你就可以用go buildgo-winres正常编译了,只需要记住设置-ldflags=-H=windowsgui

展开查看全部

相关问题