What resource ID should I give my application’s main icon?

Applying what we know about how Explorer finds the "first" icon in a file. The post What resource ID should I give my application’s main icon? appeared first on The Old New Thing.

Apr 24, 2025 - 19:07
 0
What resource ID should I give my application’s main icon?

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_APPLICATION, 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_APPLICATION 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 Load­Icon and pass the special value IDI_APPLICATION (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_ERROR), a question mark icon as icon 32514 (IDI_QUESTION), 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.

The post What resource ID should I give my application’s main icon? appeared first on The Old New Thing.