• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

Icon index

Microsoft VC++ 6.0 /SP3

I'm creating the shell shortcuts for my app. I need to specify an icon index for the shortcut.
The question is: what should I do to assign the certain icon index to the icon resource?

Usually, I declare the icons by names, not by numbers (see below).
I tried both ways. I placed the icons to the beginning of the RC file and in alphabetical order.
Nothing helps.

Here is my RC file. The first two icons must have the indexes 0 and 1.

I tried:

1)   1  ICON "App.ico"        
     2  ICON "Apptrace.ico"  

Result:
Encprop_Icon has index 0
Lock_Icon has index 1
(Encprop_Icon is a first in the alphabetical order among all other icons, Lock_Icon is a second one).


2)   App1  ICON "App.ico"        
     App2  ICON "Apptrace.ico"  

Result:
App1 has index 0 (as required).
Lock_Icon has index 1

What is going on?



// RC file ********************
#include <commctrl.h>
#include <winnt.rh>

1        ICON "App.ico"          // MUST HAVE INDEX 0
2        ICON "Apptrace.ico"     // MUST HAVE INDEX 1

#include "Auxstr.rc"
#include "Getstr.rc"
...
#include "Logprop.rc"  // CONTAINS AN ICON "Logprop_Icon"
#include "Winerr.rc"
#include "Userinfo.rc"
#include "Verinfo.rc"

#include "Data.rc"      // CONTAINS AN ICON "Encprop_Icon"
#include "Inout.rc"     // All these files contain icons.
#include "Nuser.rc"
#include "Skt.rc"
#include "Users.rc"

... OTHER RESOURCES

MicCtrl_Icon   ICON     "Micctrl.ico"
MicMuted_Icon  ICON     "Micmuted.ico"
Lock_Icon      ICON     "Lock.ico"
Status_Bmp     BITMAP   "Status.bmp"
Call_Wav       WAVE     "Call.wav"
Chat_Cursor    CURSOR   "Chatwait.cur"
Miscprop_Icon  ICON     "Mscprop.ico"
...
0
NickRepin
Asked:
NickRepin
1 Solution
 
chensuCommented:
According to the technical article - "Icons in Win32",

"Choosing an Icon
When Windows prepares to display an icon, a desktop shortcut for example, it must parse the .EXE or .DLL file and extract the appropriate icon image. This selection is a two step process starting with the selection of the appropriate RT_GROUP_ICON resource, and ending with the selection of the proper RT_ICON image from that RT_GROUP_ICON.

Which Icon?
If an .EXE or .DLL file has only one RT_GROUP_ICON resource, the first step is trivial; Windows simply uses that resource. However, if more than one such group resource exists in the file, Windows must decide which one to use. 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. So, to be sure that a particular icon is used for an application, the developer should insure that both of the following criteria are met:

1. The icon is placed before all other icons in the RC file.

2. If the icon is named, its name is alphabetically before any other named icon, otherwise its resource identifier is numerically smaller than any other icon.


Which Image?
Once an RT_GROUP_ICON is chosen, the individual icon image, or RT_ICON resource, must be selected and extracted. Again, if there exists only one RT_ICON resource for the group in question, the choice is trivial. However, if multiple images are present in the group, the following selection rules are applied:

1. The image closest in size to the requested size is chosen.

2. If two or more images of that size are present, the one that matches the color depth of the display is chosen.

3. If none exactly match the color depth of the display, Windows chooses the image with the greatest color depth without exceeding the color depth of the display.

4. If all the size-matched images exceed the color depth of the display, the one with the lowest color depth is chosen.

5. Windows treats all color depths of 8 or more bpp as equal. For example, it is pointless to have a 16x16 256 color image and a 16x16 16bpp image in the same resource - Windows will simply choose the first one it encounters.

6. When the display is in 8bpp mode, Windows will prefer a 16 color icon over a 256 color icon, and will display all icons using the system default palette."
0
 
NickRepinAuthor Commented:
Still there is problem with the icon with index 1.

I found the workaround. I use the numeric id for the second icon and then specify its negative value as the icon index.

Anyway, thanks. Now I exactly know what to do with the icon to be displayed near the exe name in the Explorer window .

It seems that this article was written before NT4, because my NT chooses the icon to display as Win95 described here.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now