Home > Mobile >  WinAPI - LoadIcon returns a valid handle but Icon won't change
WinAPI - LoadIcon returns a valid handle but Icon won't change

Time:11-19

I'm loading my icon from a resource file like so:

wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wcex.hIconSm        = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));

I have also deleted visual studio default ico both from the resource and folder so it only has the .icos and .bmps that I've supplied. LoadIcon is working fine, but if I open the visual studio folder where my executable is, it still has the default icon from microsoft and not the one I loaded. enter image description here

If I move my executable to any other folder it will change to the iconI set, why is this? Why is VS still using the default icon even though I deleted?

CodePudding user response:

if I open the visual studio folder where my executable is, it still has the default icon from microsoft

The icon shown by other programs such as Windows explorer has nothing to do with the code you show -- your program isn't even running.

The code you showed changes the icon associated with your window class, and therefore your main window. This will appear in the upper-left corner of your window, the taskbar, etc.... while your program is running.

The icon shown when looking at your EXE file is based only on the first icon resource in numeric order (the symbolic names the Resource Editor lets you assign have no effect on which icon is "first").

Based on your additional note

If I move my executable to any other folder it will change to the icon I set

it seems that you have successfully changed the icon, and the only reason it is showing up wrong in your build directory is a stale Windows Explorer icon cache.

See the SuperUser Q&A Refresh Icon Cache Without Rebooting for instructions on how to force the cache to update.

  • Related