|
1 | 1 | --- |
2 | 2 | title: "How to: Include Resources at Compile Time (C++)" |
3 | 3 | ms.date: "11/04/2016" |
4 | | -f1_keywords: ["vs.resvw.resource.including", "vc.resvw.resource.including"] |
5 | | -helpviewer_keywords: ["comments [C++], compiled files", "resources [C++], including at compile time", "projects [C++], including resources", "#include directive", "include directive (#include)"] |
| 4 | +f1_keywords: ["vs.resvw.resource.including", "vc.resvw.resource.including", "vc.editors.resourceincludes"] |
| 5 | +helpviewer_keywords: ["comments [C++], compiled files", "resources [C++], including at compile time", "projects [C++], including resources", "#include directive", "include directive (#include)", "Resource Includes dialog box [C++]", "rc files [C++], changing storage", "symbol header files [C++], changing", ".rc files [C++], changing storage", "symbol header files [C++], read-only", "symbols [C++], symbol header files", "directories [C++], specifying include paths for resources", "include files [C++], specifying for resources", "resources [C++], including in projects"] |
6 | 6 | ms.assetid: 357e93c2-0a29-42f9-806f-882f688b8924 |
7 | 7 | --- |
8 | 8 | # How to: Include Resources at Compile Time |
9 | 9 |
|
10 | | -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](../windows/resource-includes-dialog-box.md). |
| 10 | +Normally it's 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. |
11 | 11 |
|
12 | 12 | There are several reasons to place resources in a file other than the main .rc file: |
13 | 13 |
|
14 | | -- To add comments to resource statements that will not get deleted when you save the .rc file. |
| 14 | +- To add comments to resource statements that won't get deleted when you save the .rc file. |
15 | 15 |
|
16 | | - The resource editors do not directly read .rc or `resource.h` files. The resource compiler compiles them into .aps files, which are consumed by the resource editors. This file is a compile step and only stores symbolic data. As with a normal compile process, information that is not symbolic (for example, comments) is discarded during the compile process. Whenever the .aps file gets out of synch with the .rc file, the .rc file is regenerated (for example, when you Save, the resource editor overwrites the .rc file and the `resource.h` file). Any changes to the resources themselves will remain incorporated in the .rc file, but comments will always be lost once the .rc file is overwritten. |
| 16 | + The resource editors don't directly read .rc or `resource.h` files. The resource compiler compiles them into .aps files, which are consumed by the resource editors. This file is a compile step and only stores symbolic data. As with a normal compile process, information that isn't symbolic (for example, comments) is discarded during the compile process. Whenever the .aps file gets out of synch with the .rc file, the .rc file is regenerated (for example, when you Save, the resource editor overwrites the .rc file and the `resource.h` file). Any changes to the resources themselves will remain incorporated in the .rc file, but comments will always be lost once the .rc file is overwritten. |
17 | 17 |
|
18 | | -- To include resources that have already been developed and tested and do not need further modification. (Any files that are included but don't have an .rc extension will not be editable by the resource editors.) |
| 18 | +- To include resources that have already been developed and tested and don't need further modification. (Any files that are included but don't have an .rc extension won't be editable by the resource editors.) |
19 | 19 |
|
20 | | -- 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. |
| 20 | +- To include resources that are being used by several different projects, or that are part of a source code version-control system, and so must exist in a central location where modifications will affect all projects. |
21 | 21 |
|
22 | 22 | - 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 Windows SDK documentation for more information. |
23 | 23 |
|
24 | | -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](../windows/resource-includes-dialog-box.md). The *Projectname*.rc2 file created in the \res subdirectory of a new project is used for this purpose. |
| 24 | +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. |
25 | 25 |
|
26 | | -### To include resources in your project at compile time |
| 26 | +You can use the **Resource Includes** dialog box in a C++ project to modify the environment's normal working arrangement of storing all resources in the project .rc file and all [symbols](../windows/symbols-resource-identifiers.md) in Resource.h. |
27 | 27 |
|
28 | | -1. Place the resources in a resource script file with a unique file name. Do not use *projectname*.rc, because this is the file name used for the main resource script file. |
| 28 | +To open the **Resource Includes** dialog box, right-click an .rc file in [Resource View](../windows/resource-view-window.md), then choose **Resource Includes** from the shortcut menu. This dialog box has the following properties: |
29 | 29 |
|
30 | | -2. Right-click the .rc file (in [Resource View](../windows/resource-view-window.md)) and choose **Resource Includes** from the shortcut menu. |
| 30 | +|Property|Description| |
| 31 | +|---|---| |
| 32 | +|**Symbol header file**|Allows you to change the name of the header file where the symbol definitions for your resource file are stored. For more information, see [Changing the Names of Symbol Header Files](../windows/changing-the-names-of-symbol-header-files.md).| |
| 33 | +|**Read-only symbol directives**|Enables you to include header files that contain symbols that shouldn't be modified during an editing session. For example, you can include a symbol file that is shared among several projects. You can also include MFC .h files. For more information, see [Including Shared (Read-Only) or Calculated Symbols](../windows/including-shared-read-only-or-calculated-symbols.md).| |
| 34 | +|**Compile-time directives**|Allows you to include resource files that are created and edited separately from the resources in your main resource file, contain compile-time directives (such as those directives that conditionally include resources), or contain resources in a custom format. You can also use the **Compile-time directives box** to include standard MFC resource files. For more information, see [Including Resources at Compile Time](../windows/how-to-include-resources-at-compile-time.md).| |
31 | 35 |
|
32 | | -3. In the **Compile-time directives** box, add the [#include](../preprocessor/hash-include-directive-c-cpp.md) compiler directive to include the new resource file in the main resource file in the development environment. |
| 36 | +> [!NOTE] |
| 37 | +> Entries in these text boxes appear in the .rc file marked by `TEXTINCLUDE 1`, `TEXTINCLUDE 2`, and `TEXTINCLUDE 3` respectively. For more information, see [TN035: Using Multiple Resource Files and Header Files with Visual C++](../mfc/tn035-using-multiple-resource-files-and-header-files-with-visual-cpp.md). |
33 | 38 |
|
34 | | - 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. Any files that are included but don't have an .rc extension will not be editable by the resource editors. |
| 39 | +Once you have made changes to your resource file using the **Resource Includes** dialog box, you need to close the .rc file and then reopen it for the changes to take effect. For more information, see [Including Resources at Compile Time](../windows/how-to-include-resources-at-compile-time.md). |
| 40 | + |
| 41 | +For information on adding resources to managed projects, see [Resources in Desktop Apps](/dotnet/framework/resources/index) in the .NET Framework Developer's Guide. |
| 42 | + |
| 43 | +## To include resources in your project at compile time |
| 44 | + |
| 45 | +1. Place the resources in a resource script file with a unique file name. Don't use *projectname*.rc, because this name is the file name used for the main resource script file. |
| 46 | + |
| 47 | +1. Right-click the .rc file (in [Resource View](../windows/resource-view-window.md)) and choose **Resource Includes** from the shortcut menu. |
| 48 | + |
| 49 | +1. In the **Compile-time directives** box, add the [#include](../preprocessor/hash-include-directive-c-cpp.md) compiler directive to include the new resource file in the main resource file in the development environment. |
| 50 | + |
| 51 | + The resources in files included in this way are made a part of your executable file at compile time. They aren't directly available for editing or modification when you're working on your project's main .rc file. Open included .rc files separately. Any files that are included but don't have an .rc extension won't be editable by the resource editors. |
| 52 | + |
| 53 | +## To specify include directories for a specific resource (.rc file) (C++) |
| 54 | + |
| 55 | +1. Right-click the .rc file in Solution Explorer and select **Properties** from the shortcut menu. |
| 56 | + |
| 57 | +1. In the **Property Pages** dialog box, select the **Resources** node in the left pane, then specify the additional include directories in the **Additional include directories** property. |
35 | 58 |
|
36 | 59 | ## Requirements |
37 | 60 |
|
38 | 61 | Win32 |
39 | 62 |
|
40 | | -## See Also |
| 63 | +## See also |
41 | 64 |
|
42 | 65 | [Resource Files](../windows/resource-files-visual-studio.md)<br/> |
43 | | -[Resource Editors](../windows/resource-editors.md) |
| 66 | +[Resource Editors](../windows/resource-editors.md)<br/> |
| 67 | +[TN035: Using Multiple Resource Files and Header Files with Visual C++](../mfc/tn035-using-multiple-resource-files-and-header-files-with-visual-cpp.md)<br/> |
| 68 | +[Symbols: Resource Identifiers](../windows/symbols-resource-identifiers.md)<br/> |
0 commit comments