How do I use SetDeviceWindowIcon()?

Phil7

Moderator
Joined
Jun 26, 2017
Is there anything you should be aware when using this function. I tried it using a icon in the data folder and I couldn't see any effect. So some questions came up:
- Which icon is changed here? The Icon in the corner of the window or the app executable icon or the one in the taskbar?
- Does it work with Visual Studio and MinGW builds (Windows)?
- Is the path to be set absolute?
- Can you change the icon in runtime or is it just effecting the build process i.e. makefile/ icon.rc
 

MikeHart

Administrator
Joined
Jun 19, 2017
Location
Germany
I tried it using a icon in the data folder and I couldn't see any effect. So some questions came up:
It should have. Use a PNG file and place it inside the data folder. What you set with SetDeviceWindowIcon is the little image in the top left of a window and the icon on the taskbar:

Cerberus X:
SetDeviceWindowIcon("icon.png")
614


Does it work with Visual Studio and MinGW builds (Windows)?
Yes, it does.

Is the path to be set absolute?
Nope, see the code example above.

Can you change the icon in runtime or is it just effecting the build process i.e. makefile/ icon.rc
This is a runtime change.

To change the icon of an exe, you need to modify the project files. Since the last release, with MingW you have to exchange the icon here:

615


You can name it differently, but then you have to change the reference in the resource.rc file.
On MSVC I still have to look into this, there it won't work like that.
Anyway, this method of changing the exe icon is temporary and subject to change.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Location
Germany
Ok, I managed to add this icon into the resource of the MSVC project.

Copy the content of the attachment into the template/msvc folder of the GLFW target.
 

Attachments

Phil7

Moderator
Joined
Jun 26, 2017
Thank you!
So SetDeviceWindowIcon() is only useful, if I want to change the window icon during runtime.
At least with MinGW I can set all icons on windows by changing it with windres
 

Phil7

Moderator
Joined
Jun 26, 2017
I couldn't test msvc for now. But for minGW I think I found something:
1. Sometimes it was necessary to delete the 'build' folder inside 'glfw3/gcc_winnt' to trigger a new resource.o
2. There seems to be some kind of cache for the display of the exe icon. I don't know how to reset this , but the new Icon is displayed correctly after a system reboot.

3. Something else is the suggestion to change the content of resource.rc to
Cerberus X:
id ICON "CerberusIcon.ico"
GLFW_ICON ICON "CerberusIcon.ico"
This way the icon is also displayed in the corner of the window and in the taskbar. I also changed the default name of the icon to CerberusIcon to make it speak a bit more, as per default file extensions are not shown on windows as far as I know.
 
Top Bottom