lxn / win

A Windows API wrapper package for the Go Programming Language
Other
1.19k stars 312 forks source link

how to set the icon on the title bar #53

Open rinetd opened 6 years ago

rinetd commented 6 years ago

20180610202948 20180610203615

i found some code like this ,but i don't known how to use it. SetClassLong(hwnd,GCL_HICON,(LONG)LoadIcon(hinstance, IDI_ICON ));

ryujimiya commented 6 years ago

Hi, rinetd!

if you use lxn/walk and not directly use lxn/win, you may load the icon file and put it to window like this;

    icon, iconErr := walk.Resources.Icon("foo.ico")

    err := MainWindow{
        AssignTo: &mainWin,  
        Title:    "MainWindow",
        Icon:     icon,
        (snip)
    }.Create()

if you want to load icon from resources, first you have to rsrc

rsrc -arch amd64 -manifest foo.exe.manifest -ico foo.ico -o rsrc.syso

and, load it like this:

    icon, iconErr := walk.Resources.Icon("3")
lxn commented 5 years ago

You can do it like this, too:

err := MainWindow{
        AssignTo: &mainWin,  
        Title:    "MainWindow",
        Icon:     "foo.ico",
        (snip)
    }.Create()