Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How setup a title bar icon with Gio

Tags:

windows

go

I am having a problem with Gio UI (https://gioui.org/).

My test App

As you see there the window icon is not set, and there are no options to set it.

When you create a new window you can only set the title:

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

But if I understand correctly the icon should be loaded from resources manifest:

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

//

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

To build resource manifest I am using go winres: https://github.com/tc-hib/go-winres

I have setup correctly in the winres.json the app icon and the icon in the taskbar as explained in the guide.

I think there should be a way to set also the window icon in app title, but I can't find which key should I specify in the json:

{
  "RT_GROUP_ICON": {
    "APP": {
      "0000": [
        "icon_64.png",
        "icon_48.png",
        "icon_32.png",
        "icon_16.png"
      ]
    },
    "OTHER": {
      "0000": "icon.png"
    },
    "#42": {
      "0409": "icon_EN.ico",
      "040C": "icon_FR.ico"
    }
  }
}
like image 412
Stefano Balzarotti Avatar asked Oct 28 '25 00:10

Stefano Balzarotti


1 Answers

The official way to do it is to use gogio tool that unluckily is very poorly documented and has a lot of limitations compared to go-winres.

Install it with with go install gioui.org/cmd/gogio@latest

Then compile your application with this command:

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

Change architecture and paths according to your needs.

Anyway as far as I understand gogio supports only png and it will generate automatically all needed resolutions.

Since I want to use go-winres, I have just used Resource Hacker to decompile the exe resources.

I found that to set the icon you need to set winres.json like this:

{
  "RT_GROUP_ICON": {
    "#1": {
      "0409": "myicon_EN.ico"
    }
  },
  "RT_MANIFEST": {
    "#1": {
      "0409": 
// Your settings
  }
}

Then you can compile normally with go build and go-winres, just remember to set -ldflags=-H=windowsgui

like image 113
Stefano Balzarotti Avatar answered Oct 29 '25 17:10

Stefano Balzarotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!