Solved

Icon index

Posted on 2000-03-27
2
494 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
ID: 2661345
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
ID: 2662163
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 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