Search code examples
c++windowswxwidgets

Windows C++ wrong icon being displayed in explorer with multiple icons in resources file


I have a wxWidgets program where the resources.rc file has two icons in it.

  • Program icon
  • Exit program icon

The contents of my resources.rc is:

#include "wx/msw/wx.rc"
#include "common/version.h"

// Icons
// Note the icon is an embedded icon
// i.e. Windows will be able to pick an appropriate icon size from:
// 256,128,96,64,48,32,24,16
MyProgram_ICO ICON "..\\res\\app.ico"
EXIT_ICO ICON "..\\res\\exit.ico"


// VS_VERSION_INFO etc

Explorer is showing my program with EXIT_ICO. Clearing the explorer cache, removing the EXIT_ICO entry, clean and build then shows the correct icon. But if I include it again, it picks the EXIT_ICO as the program icon.

My understanding of this is it would pick the first ICON entry in the resources file. I have also tried flipping the order to no avail. I don't understand why it's picking the EXIT_ICO one.

My program is still in development, so there will be more icons added to the resources file. The resources file is included in the SRC variable in CMake so it is being built with it

My program is being developed with wxWidgets, Visual Studio 2022 and CMake. I am developing the program in Windows 11.

Screenshots:

with wrong icon in explorer

the correct icon when running the program


Solution

  • As pointed out by @Ripi2 in the comments, wxWidgets provides the crucial nugget of information as such:

    // note that the icon used by the Explorer (i.e. the programs icon) is the
    // first icon in the executable and the icons are sorted both by their order
    // and alphabetically (!), so put this icon first and give it a name
    // starting with "a"
    

    Source

    And the correct icon gets displayed in explorer now:

    correct icon

    My resources.rc file now looks like this:

    #include "wx/msw/wx.rc"
    #include "common/version.h"
    
    // Icons
    // Note the icon is an embedded icon
    // i.e. Windows will be able to pick an appropriate icon size from:
    // 256,128,96,64,48,32,24,16
    aMyProgram_ICO ICON "..\\res\\taskies.ico"
    EXIT_ICO ICON "..\\res\\exit.ico"