3
votes

I have been trying to get an icon added to my application as a resource, so that it is displayed with my application in VS 2012 Express using c++. So far I have picked up the following code to add to my rc file from other questions and forums.

IDI_APP ICON "resources/Icon.ico"

The icon is displayed on the desktop with the exe, and on the taskbar when the program is running. However in certain situations such as on the task manager the icon for the application dies not show up and instead the default program icon is displayed. I was wondering if anyone knows how to alter my code so that the icon is always associated with my program. I have heard that the problem may result from needing different sized icons however I have many sizes of icons within my ico file created with the program IcoFX. I was also wondering if I needed to programmatically set the icon for it to work in any place the application is associated with. I have tried rebuilding and renaming my program to update the icon in the shell. I am using a sfml window instead of the winapi and a HWND window.

1
Google "reset shell icon cache". A quick check is renaming your program.Hans Passant
i renamed my program, but it didn't helppopgalop

1 Answers

1
votes
  1. Double check that you created a single .ico file with multiple resolutions, usually 16x16, 32x32, 48x48, 96x96.

  2. Load your icon with something like

    ICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
    
  3. Notify with Windows messages of the icon

    //Change both icons to the same icon handle.
    SendMessage(hwnd, WM_SETICON, ICON_SMALL, hIcon);
    SendMessage(hwnd, WM_SETICON, ICON_BIG, hIcon);
    
    //This will ensure that the application icon gets changed too.
    SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_SMALL, hIcon);
    SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_BIG, hIcon);
    
  4. Finally reset the shell icon cache as described here or by just restarting/logging out.

Additional resources and references:

https://stackoverflow.com/a/19656000/1938163

https://stackoverflow.com/a/2723270/1938163