Thursday, March 26, 2020

Icon in Application Golang, using rsrc & lxn/walk

 


 

Taken from https://stackoverflow.com/questions/25602600/how-do-you-set-the-application-icon-in-golang as my note



You can use a tool like akavel/rsrc in order to generate a .syso file with specified resources embedded in .rsrc section, aimed for consumption by Go linker when building Win32 excecutables.

See as an example the lxn/walk application, which embeds other metadata in its executable.

rsrc [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso
-ico="":

comma-separated list of paths to .ico files to embed


For more detail in GOLANG APPS from https://github.com/lxn/walk/issues/361#issuecomment-468228063



his only sets the Icon for the console window but not for the Walk GUI window.
To have those also use that same Icon use:

var appIcon, _ = walk.NewIconFromResourceId(3) // number 3 is resource ID printed by RSRC.exe while making accounting.syso

and then add this to each MainWindow or Dialog:

 Icon:     appIcon,

The build would look something like this example (after which the icon also works from in the Visual Studio Code IDE)

cd C:\Build\accounting
C:\Build\Go_tools\rsrc.exe -manifest accounting.manifest -ico accounting.ico -o accounting.syso
go build -ldflags -H=windowsgui