Using Resources on Multiple Platforms
Visual Studio enables you to have one device project target multiple platforms, such as Pocket PC and Smartphone. Due to the user interface (UI) differences between the platforms, each platform needs its own resource script (.rc) file in the project.
Multiple Resource Files
There are two ways that you can set your device project to target multiple platforms:
With the application wizards at the time of project creation.
After project creation.
If you select multiple platforms on the Platforms page in the application wizard of your project, a resource file will be generated and configured for each of your platforms. For example, if you select Pocket PC and Smartphone as target platforms, the Pocket PC resource file will be excluded from the build for the Smartphone platform, and the Smartphone resource file will be excluded from the build for the Pocket PC platform.
However, if you add a platform after project creation, you will have to manually add a platform and resource file.
Adding a New Platform
To add a new platform
On the Build menu, click Configuration Manager.
In the Active Solution Platform box, click <New...>.
Select the platform that you want to add to your project, select the platform that you want to copy settings from, and click OK.
Note
If you copy settings from <Default>, the project properties for that platform will be empty. It is recommended that you copy settings from a similar platform, and then change the project properties as needed. For example, if you are adding Smartphone as a platform, copy settings from the Pocket PC platform.
Click Close.
Adding a New Resource File
Now that you have a new platform, you will have to add a resource file for that platform.
To add a resource file for a new platform
On the Project menu, click Add New Item.
In the Add New Item dialog box, click Resource, and then in the Templates pane, click Resource File (.rc).
In the Name box, type a name for your file, and click Add.
A new header (.h) file that corresponds to your new resource script (.rc) file is added to your project.
Excluding Resource Files From Builds
When you build a project for a target platform, you do not want resource files from another platform included. You can exclude files from builds based on the targeted platform.
To exclude resource files from builds
Right-click the resource script (.rc) file, and click Properties.
In the Platform box, select the first platform in the list.
On the General property page, select Yes in the Excluded From Build box if you do not want this .rcfile included when the project is built for the selected platform.
Repeat the previous step for each platform configuration, making sure to only exclude the resource files that do not belong to the currently selected platform.
Repeat steps all the previous steps (1-4) for each .rc file in the project.
In Solution Explorer, you will notice a red mark on the icon of each file being excluded from the build for the currently selected platform.
Changing the Project Properties of Your New Platform Configuration
Now that your resource files are set up for your platforms, you must make sure that the project properties are correct for your new platform configuration. If you copied settings from a similar platform, you may not have many settings to change, but if you selected <Default>, you will have to manually add all your settings. For this example, you can assume that you added a new Smartphone 2003 (ARMV4) platform to your project, and copied the settings from the Pocket PC 2003 (ARMV4) platform.
To change your project properties
On the Project menu, click Properties.
Expand the C/C++ node, and click Preprocessor.
In the Preprocessor Definitions box, change POCKETPC2003_UI_MODEL to SMARTPHONE2003_UI_MODEL, and click OK.
Note
If you have added a different platform, or have copied settings from a different platform, you may have to change more settings.
Adding the #ifdef Directive to the Header File
The main header file of your project must check for the UI model preprocessor definition that you set in the previous procedure, and only includes the corresponding resource file.
To add the #ifdef directive to the header file
Open ProjectName.h.
After the #ifdef for your original platform's UI model, add the following code:
#ifdef SMARTPHONE2003_UI_MODEL #include "ResourceFileName.h" #endif