|
1 | 1 | --- |
2 | 2 | title: "How to: Create a Resource (C++)" |
3 | 3 | ms.date: "11/04/2016" |
4 | | -helpviewer_keywords: ["toolbars [C++], resources", "resource toolbars", "resources [C++], creating"] |
| 4 | +f1_keywords: ["vs.resourceview.F1", "vc.editors.insertresource", "vc.editors.newcustomresource"] |
| 5 | +helpviewer_keywords: ["toolbars [C++], resources", "resource toolbars", "resources [C++], creating", "resources [C++], viewing", "Resource View window", "resources [C++], adding", "Add Resource dialog box [C++]", "Custom Resource Type dialog box [C++]"] |
5 | 6 | ms.assetid: aad44914-9145-45a3-a7d8-9de89b366716 |
6 | 7 | --- |
7 | | -# How to: Create a Resource |
| 8 | +# How to: Create a Resource (C++) |
| 9 | + |
| 10 | +The **Resource View** window displays the resource files included in your projects. Expanding the top folder (for example, Project1.rc) shows the resource types within that .rc file. Expanding each resource type shows the individual resources of that type. |
| 11 | + |
| 12 | +> [!NOTE] |
| 13 | +> This information does not apply to resources in Universal Windows Platform apps. For more information about that, see [App resources and the Resource Management System](/windows/uwp/app-resources/). |
8 | 14 |
|
9 | 15 | > [!NOTE] |
10 | 16 | > **Resource View** is not supported in Express editions. |
11 | 17 |
|
12 | | -### To create a new resource in Resource View |
| 18 | +For information on adding resources to managed projects, see [Resources in Desktop Apps](/dotnet/framework/resources/index) in the *.NET Framework Developer's Guide*. |
13 | 19 |
|
14 | | -1. With focus on your .rc file in [Resource View](../windows/resource-view-window.md), click the **Edit** menu and choose **Add Resource** (or right-click the .rc file in **Resource View** and choose **Add Resource** from the shortcut menu). |
| 20 | +> [!NOTE] |
| 21 | +> If your project doesn't already contain an .rc file, please see [Creating a New Resource Script File](../windows/how-to-create-a-resource-script-file.md). |
15 | 22 |
|
16 | | - > [!NOTE] |
17 | | - > If your project doesn't already contain an .rc file, please see [Creating a New Resource Script File](../windows/how-to-create-a-resource-script-file.md). |
| 23 | +The **Resource View** window uses the **Add Resource** dialog box to add resources to a C++ Windows desktop application project. This dialog box has the following properties: |
18 | 24 |
|
19 | | -2. In the [Add Resource dialog box](../windows/add-resource-dialog-box.md), choose the type of resource you'd like to add to your project. |
| 25 | +|Property|Description| |
| 26 | +|---|---| |
| 27 | +|**Resource Type**|Specifies the kind of resource you want to create.<br/><br/>You can expand the cursor and dialog box resource categories to reveal additional resources. These resources are located in ...\Microsoft Visual Studio `version`\VC\VCResourceTemplates\\<LCID\>\mfc.rct. If you add .rct files, you must put them in this directory or you must specify an [include path](../windows/how-to-specify-include-directories-for-resources.md) for them. The resources in those files then appear at the second level under the appropriate category. There's no preset limit to the number of .rct files you can add.<br/><br/>The resources shown at the top level in the tree control are the default resources that are provided by Visual Studio.| |
| 28 | +|**New**|Creates a resource based on the type you've selected in the **Resource Type** box. The resource opens in the appropriate editor. For example, if you create a dialog resource, it opens in the [dialog editor](../windows/dialog-editor.md).| |
| 29 | +|**Import**|Opens the **Import** dialog box in which you can navigate to a resource you'd want to import into your current project. You can import a bitmap, icon, cursor, HTML resource file, sound (.WAV) resource file, or custom resource file.| |
| 30 | +|**Custom**|Opens the **New Custom Resource** dialog box in which you can create a custom resource. Custom resources can be edited in the Binary editor only.| |
20 | 31 |
|
21 | | -### To create a new resource in Solution Explorer |
| 32 | +The **New Custom Resource** dialog box enables you to create a new custom resource in a C++ project. This dialog box has the following property: |
22 | 33 |
|
23 | | -1. In **Solution Explorer**, right-click the project folder and choose **Add**, then click **Add Resource** on the shortcut menu. |
| 34 | +|Property|Description| |
| 35 | +|---|---| |
| 36 | +|**Resource Type**|Provides a text box for you to enter the name of a custom resource type. Visual C++ automatically capitalizes the name when you exit the **New Custom Resource** dialog box.| |
| 37 | + |
| 38 | +When you create a new resource, Visual C++ assigns a unique name to it, for example, `IDD_Dialog1`. You can customize this resource ID by editing the properties for the resource either in the associated resource editor or in the [Properties Window](/visualstudio/ide/reference/properties-window). |
24 | 39 |
|
25 | | - If you do not already have an .rc file in your project, this step will create one. You can then repeat this step to add specific resource types to the new .rc file. |
| 40 | +You can create a resource as a new default resource (a resource that isn't based on a template) or as a resource patterned after a [template](../windows/how-to-use-resource-templates.md). |
26 | 41 |
|
27 | | -2. In the [Add Resource dialog box](../windows/add-resource-dialog-box.md), choose the type of resource you'd like to add to your project. |
| 42 | +> [!NOTE] |
| 43 | +> Do not specify a resource name or ID that is reserved by Visual Studio. The reserved names are DESIGNINFO, HWB, and TEXTINCLUDE, and the reserved ID is 255. |
28 | 44 |
|
29 | | -### To create a new resource in Class View |
| 45 | +## To open the resource view window |
30 | 46 |
|
31 | | -1. In [Class View](/visualstudio/ide/viewing-the-structure-of-code), right-click your class and choose **Add**, then click **Add Resource** from the shortcut menu. |
| 47 | +Select **Resource View** on the **View** menu. |
32 | 48 |
|
33 | | -2. In the [Add Resource dialog box](../windows/add-resource-dialog-box.md), choose the type of resource you'd like to add to your project. |
| 49 | + \- or - |
34 | 50 |
|
35 | | -### To create a new resource from the Project menu |
| 51 | +Press **Ctrl** + **Shift** + **E**. |
36 | 52 |
|
37 | | -1. From the **Project** menu, choose **Add Resource**. |
| 53 | +> [!TIP] |
| 54 | +> You can right-click on the **Resource View** window to launch a shortcut menu of commands. You can also double-click on the title bar to dock or undock the window. Right-clicking on the title bar will give you additional commands that allow you to control the behavior of the window. For more information, see [Windows Management](/visualstudio/ide/customizing-window-layouts-in-visual-studio). |
38 | 55 |
|
39 | | -When you create a new resource, Visual C++ assigns a unique name to it, for example, `IDD_Dialog1`. You can customize this resource ID by editing the properties for the resource either in the associated resource editor or in the [Properties Window](/visualstudio/ide/reference/properties-window). |
| 56 | +## To create a new resource in Resource View |
| 57 | + |
| 58 | +1. With focus on your .rc file in **Resource View**, select the **Edit** menu and choose **Add Resource** (or right-click the .rc file in **Resource View** and choose **Add Resource** from the shortcut menu). |
| 59 | + |
| 60 | + > [!NOTE] |
| 61 | + > If your project doesn't already contain an .rc file, please see [Creating a New Resource Script File](../windows/how-to-create-a-resource-script-file.md). |
| 62 | +
|
| 63 | +1. In the **Add Resource** dialog box, choose the type of resource you'd like to add to your project. |
| 64 | + |
| 65 | +## To create a new resource in Solution Explorer |
| 66 | + |
| 67 | +1. In **Solution Explorer**, right-click the project folder and choose **Add**, then click **Add Resource** on the shortcut menu. |
| 68 | + |
| 69 | + If you don't already have an .rc file in your project, this step will create one. You can then repeat this step to add specific resource types to the new .rc file. |
| 70 | + |
| 71 | +2. In the **Add Resource** dialog box, choose the type of resource you'd like to add to your project. |
| 72 | + |
| 73 | +## To create a new resource in Class View |
| 74 | + |
| 75 | +1. In [Class View](/visualstudio/ide/viewing-the-structure-of-code), right-click your class and choose **Add**, then select **Add Resource** from the shortcut menu. |
| 76 | + |
| 77 | +2. In the **Add Resource** dialog box, choose the type of resource you'd like to add to your project. |
40 | 78 |
|
41 | | -You can create a resource as a new default resource (a resource that is not based on a template) or as a resource patterned after a [template](../windows/how-to-use-resource-templates.md). |
| 79 | +## To create a new resource from the Project menu |
42 | 80 |
|
43 | | -For information on adding resources to managed projects, please see [Resources in Desktop Apps](/dotnet/framework/resources/index) in the *.NET Framework Developer's Guide*. |
| 81 | +From the **Project** menu, choose **Add Resource**. |
44 | 82 |
|
45 | 83 | ## Requirements |
46 | 84 |
|
47 | 85 | Win32 |
48 | 86 |
|
49 | | -## See Also |
| 87 | +## See also |
50 | 88 |
|
| 89 | +[Working with Resource Files](../windows/working-with-resource-files.md)<br/> |
51 | 90 | [Resource Files](../windows/resource-files-visual-studio.md)<br/> |
52 | 91 | [Resource Editors](../windows/resource-editors.md)<br/> |
53 | | -[Add Resource Dialog Box](../windows/add-resource-dialog-box.md) |
|
0 commit comments