The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @nadineswagerman: Iemand mailde me dat een 13-jarig meisje mijn novelle had uitgekozen om te lezen/bespreken op school. Het boek bevat 9… 5 hours ago
    • RT @jilles_com: Afgelopen 10 dagen hebben we door NL gereisd, elke dag een nieuw hotel en op heel veel locaties gegeten. In 60% van de geva… 5 hours ago
    • RT @FTM_nl: Sywert van Lienden plaatste bewust een serie tweets om het ministerie onder druk te zetten om de omstreden mondkapjesdeal met h… 5 hours ago
    • RT @ArmsControlWonk: China just used a rocket to put a space plane in orbit and the space plane glided back to earth. Orbital bombardment i… 5 hours ago
    • RT @shossontwits: O jee. Nu dit weer. 6 hours ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,482 other followers

Windows applications: Icons and the Shell; names, sizes, etc.

Posted by jpluimers on 2015/12/23

When adding Icons to your Windows applications a few things matter.

Selecting the icon resource

The icon selected by the Windows Shell (for modern Windows versions usually Windows Explorer), is the one with the lowest ID. When there is no icon with an ID, it selects the icon with the lowest name.

Icons in Windows can have both IDs and names. Even though API calls like LoadIcon have an lpIconName parameter, you can convert the ID to a name using MAKEINTRESOURCE.

There is a difference between the format of an ICO file and the icon resource (technically two things: RT_GROUP_ICON resource directory and an RT_ICON resource for each image) contains a list of icon images.

The selection process is on the RT_GROUP_ICON, and then within the group on the ICON itself.

For the RT_GROUP_ICON process, modern Windows versions still use the algorithm used by Windows 95 (not that by Windows NT):

Windows NT simply chooses the first resource listed in the application’s RC script. On the other hand, Windows 95’s algorithm is to choose the alphabetically first named group icon if one exists. If one such group resource does not exist, Windows chooses the icon with the numerically lowest identifier.

For a Delphi application the icon shown must be named MAINICON, since the below source fragment has been in TApplication.Create(…) like forever:

FIcon.Handle := LoadIcon(MainInstance, 'MAINICON');

Which means that if you want the Windows Shell (usually Explorer) to select that one, all other icon resources in your executable must have names that sort after MAINICON.

Selecting the icon within a resource

For the individual icon, the process is more complex. Even the summary is. To summarise the summary to select an icon for the requested size:

  1. Prefer the image closest in size.
  2. When more images of that size are present, match on the best color depth for the display.
  3. When no color depth matches, prefer the image with the greatest color depth not exceeding the color depth of the display.
  4. When all exceed the color depth, prefer the lowest color depth.

For color depth, treat 8 or more bits per pixel as equal. So there is no advantage of including a 16×16 256-color image and a 16×16 16-color image in the same resource — the system will simply choose the first one it encounters. When the display is in 8-bpp mode, the system will choose a 16-color icon over a 256-color icon, and will display all icons using the system default palette.

I’m not completely confident how 32-bit precisely fits in this scheme. If someone knows, please let me know and I’ll include the information.

I usually take 32-bit color images here which are actually True Color 24-bit + alpha channel RGBA images.

What about requested size?

Actually there are a lot of sizes that Windows can request, and there are many articles about it, some of which contradict each other.

From what I assembled, these are the sizes you need to run on Windows XP / Server 2003 and up:

  • 16×16
  • 20×20
  • 24×24
  • 32×32
  • 40×40
  • 48×48
  • 64×64
  • 96×96
  • 128×128
  • 256×256 (for Windows XP / Server 2003: do not compress this size)

I might be wrong, so here are some links:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: