Conditional compilation of resource file for different icons in visual studio C++

Combining the instruction from the post here and a blog here, I summarize the steps to dynamically use different icons in resource script file (.rc file).

1. Open your project in Visual Studio 2010
2. Right click on resource script file (e.g. app.rc) and select “Properties”
3. At the top of the property page, select one product solution configuration like “Product A” or “Product B”. This is similar to “Win32”, or “x64”, but for different product.
4. In the left menu bar, select [Configuration Properties] / [Resources] / [General].
5. In the “Preprocessor Definitions” field, add “Product_A” for “Product A” configuration and “Product_B” for “Product B” configuration . The field value will become “NDEBUG;%(PreprocessorDefinitions);Product_A”.
6. Click OK to close the window.
7. Right click on resource script file (e.g. app.rc) and select “View Code”.
8. In the code editor, add #ifdef and #elif to conditionally include resources when compiling. Use “Product_A” and “Product_B” preprocessor definitions that we defined just now.

Here is a sample code:

#ifdef Product_A
	IDI_MAINFRAME_ICON  ICON  "..\\Software\\res\\idr_main_A.ico"
#elif Product_B
	IDI_MAINFRAME_ICON  ICON  "..\\Software\\res\\idr_main_B.ico"
	IDI_MAINFRAME_ICON  ICON  "..\\Software\\res\\idr_main.ico"

9. Save the resource script file and compile the project in different platforms.