A customer wanted to know what resource ID to assign to their application’s main icon.
There was one faction within the company that felt that the resource ID should be 1, because it’s the first icon.
There was another faction that felt that the resource ID should be 32512, because that is the value of IDI_
, which is documented as “Default application icon.”
Furthermore, when they did a survey of what other programs did, they saw that the resource IDs were all over the place. While it’s true that a lot of programs used resource ID 1, some used resource ID 2, and Visual Studio uses resource ID 32512.
Who’s right?
Recall the algorithm by which Explorer finds the “first” icon in a file.
- Choose the alphabetically first named group icon, if available.
- Else, choose the group icon with the numerically lowest identifier.
Therefore, everybody is right, for certain values of “right”.
Suppose you know that a list of items is always shown in sorted order by their ID numbers. How should you assign ID numbers so that the item you like most is always at the top?
Answer: Give it the smallest ID number.
This could be accomplished many ways.
You could given it an ID number of 2 and take care never to give anybody an ID number of 1.
You could given it an ID number of 32512 and take care never to give anybody an ID number between 1 and 32511.
But probably the simplest way to accomplish this is to give it an ID number of 1.
Note that if your module contains named resources, then those take priority over numbered resources for the purpose of choosing the first icon, in which case giving your icon the resource ID of 1 wasn’t good enough, since named icons come before numbered icons.
Bonus chatter: The 32512 faction argued that the documentation on icons explicitly lists IDI_
as the default application icon, but they are reading the table wrong. This is not saying that the default application icon is the one at location 32512. It’s saying that “If you want to ask the system to give you a copy of the default icon, call LoadIcon
and pass the special value IDI_
(32512).” After all, if the requirement applied as they interpreted it, then that would mean that every application must put an error icon as icon 32513 (IDI_
), a question mark icon as icon 32514 (IDI_
), and so on. But nobody does that.
Bonus speculation: My guess for why Visual Studio uses 32513 as the resource ID for the icon is merely that the system provided a convenient name for that number so they didn’t have to add the line
#define IDI_APP 1
to their resource.h
. In other words, it was just a bit of laziness.
@GL I’m almost 100% sure LoadIcon will just fail returning zero for an icon that’s not there. Which is enough to do the trick, since for zero-valued WNDCLASSEX.hIcon and friends the top-level window will have the IDI_APPLICATION anyway. Besides, LoadIcon has to have a way to tell the calling application the icon it requests doesn’t exist, so returning fallback icon handle isn’t a good idea.
BTW, what’s so ”invalid” about an ”empty” (icon-wise?) application? There clearly is a fallback in the system and icons are not generally critical for an application to be usable.
I think i’m correct that visual studio could be called an IDE, in which case using IDi-Error makes ‘perfect’ sense
I was using 0 as an icon ID for a very long time until one of the recent Windows 11 updates stopped showing it on the taskbar. Now I use IDI_ICON1 because this is what Qt expects me to use.
Well color me surprised. I didn’t know ID 0 can be used.
Using 2 is best. Using 1 is a bad idea because then you get in trouble if you use the -1 icon location syntax in the registry and somebody uses ExtractIcon with your path (this issue has already been covered on this blog, -1 returns the icon count).
You don’t technically need to specify more than the path for the first icon but the negative resource syntax will load the icon slightly faster.
I think it's helpful to tell the readers that , , etc. are the resource ID for the standard icons, and they only make sense if you pass as to . The standard icon is the icon Explorer would display for an empty (of course, invalid) EXE file. My suspicion is that those resource IDs are for a certain DLL (likely because it's where resides, so the icon is always available if you can load any icon at all).
For everyone's own EXE/DLL file, resource ID 32512 has no special meaning. (I have no idea whether...
I must be mega old school because I find the file name resource.h awkward. I almost always use _resource_.rh where _resource_.rc is the resource file, which is always named appropriately for the project.
I’m not sure if more than one project per directory still works.