Multiple icons in a single resource file

Posted on 2011-03-14
Last Modified: 2012-05-11

I have a Visual Studio 2008 solution that has multiple projects (a few executables and a lib).
I'm bundling all the resources that are used in any of the projects in a single Resource.rc (and a single resource.h) file. I tried to seperate the resources per project but that is a hassle, especially due to the "automatic" numbering of the resources which gives conflicts between the projects.

It all works fine but now i would like to have different icons for the different executables (the program icon that shows on the desktop or in the start menu). Do i still have to make a Resource.rc file per-project just for this icon? Or is there another way?

Kind Regards,
Daniel Dekkers
Question by:DoZo1971
LVL 86

Accepted Solution

jkr earned 250 total points
ID: 35131144
>>Do i still have to make a Resource.rc file per-project just for this icon?

Unfortunately, yes. The default icon for an executable is always the one with the lowest resource ID.

Assisted Solution

JimBeveridge earned 250 total points
ID: 35144174
I have the same problem as you. Our project uses one "Core" rc file that is included by all other resource files, but this arrangement is something of a headache to maintain because I always have to consider the scope of any resource I create.

However, there is another way to do it. If each of your applications is built separately, but they all use a common rc file, then you can use the "Condition" in the resource compiler to determine which icon is included for a particular build. The condition is based on definitions from the command line that are set in Project Properties / Resources / General / Preprocessor defintions. For example, one of our apps includes the Preprocessor definition SERVER. In the resource file, the condition for one of the dialogs is set to SERVER to include that dialog for that app.

This works for all types of resources. To see the Condition field, select any resource and look at the Properties window for that resource.


Author Comment

ID: 35149214
Hi Jim,

This "condition" method sounds smart. So if i understand correctly i would have to add all the icons for all possible projects with low resource ids (lower than the other (non icon) resources). Say 10, 11, 12, 13, 14,.. and then include/exclude icons (depending on build) so that the right one still has the lowest id and will take the role of program icon. What is the exact syntax of the condition (in the resource) to include or exclude a particular resource?

Kind Regards,
Daniel Dekkers
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).


Expert Comment

ID: 35149258
When using Conditions, all of the icons can have the same resource ID, as long as only one of them appears in any given exe or dll.

The Condition is just a preprocessor definition name. In my example, the condition was just SERVER.

Author Comment

ID: 35149417
Ok ,thanks i'll try it out. First i have to create the core Resource.rc again, i've split it up due to the icon problem, plus, the last time i actually made the core Resoure.rc all dialogs got crippled. So i think i'll do it in steps now, first making exact copies of Resource.rc for the different projects, see if anything goes wrong, before collapsing it to a single core.

By the way... "ResOrg" is a big help to renumber the symbols and identify problems in resource.h files.
LVL 40

Expert Comment

ID: 36518478
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

14 Experts available now in Live!

Get 1:1 Help Now