Solved

Icon index

Posted on 2000-03-27
2
478 Views
Last Modified: 2013-12-03
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
Comment
Question by:NickRepin
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
Comment Utility
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
 
LVL 15

Author Comment

by:NickRepin
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now