Share via


Including Resources from Other Files

OverviewHow Do I

Normally it is easy and convenient to work with the default arrangement of all resources in one resource script (.rc) file. However, you can add resources in other files to your current project at compile time by listing them in the Compile-time directives box in the Resource Includes dialog box.

There are several reasons to place resources in a file other than the main .rc file:

  • To include resources that have already been developed and tested and do not need further modification.

  • To include resources that are being used by several different projects, or that are part of a source code version-control system, and thus must exist in a central location where modifications will affect all projects.

  • To include resources (such as RCDATA resources) that are in a custom format. RCDATA resources may have special requirements. For example, you cannot use an expression as a value for the nameID field. See the Win32 SDK documentation for more information.

  • To include statements in your resource file that execute conditionally at compile time using compiler directives such as #ifdef and #else. For example, your project may have a group of resources that are bracketed by #ifdef _DEBUG ... #endif and are thus included only if the constant _DEBUG is defined at compile time.

  • To include statements in your resource file that modify resource-file syntax by using #define to implement simple macros.

If you have sections in your existing .rc files that meet any of these conditions, you should place the sections in one or more separate .rc files and include them in your project using the Resource Includes dialog box. The Projectname.rc2 file created in the \res subdirectory of a new project is used for this purpose.

To include resource files that will be added to your project at compile time

  1. Place the resources in a resource script file with a unique filename. (Do not use projectname.rc, since this is the filename used for the main resource script file.)

  2. From the View menu, choose Resource Includes.

  3. In the Compile-time directives box, use the #include compiler directive to include the new resource file in the main resource file in the development environment.

    The resources in files included in this way are made a part of your executable file at compile time. They are not directly available for editing or modification when you are working on your project’s main .rc file. You need to open included .rc files separately.

  4. Click OK.