Edit

Share via


How to: Manage Resources (C++)

Copy and Edit Resources

You can copy resources from one file to another without changing them, or changing the language or condition of a resource while copying it.

You can easily copy resources from an existing resource or executable file to your current resource file. To copy resources, you open both files containing resources at the same time and drag items from one file to another or copy and paste between the two files. This method works for resource script (.rc) files and resource template (.rct) files, and as executable (.exe) files.

Note

Visual C++ includes sample resource files that you can use in your own application. For more information, see CLIPART: Common Resources.

You can't drag and drop, copy, cut, or paste between resource files in the project (Resource View) and stand-alone .rc files open in document windows. You could do this in previous versions of the product. Only use the drag-and-drop method between .rc files that are open outside of the project.

To copy resources

  1. Open both resource files stand-alone. (See Use resource script files). For example, open Source1.rc and Source2.rc.

  2. Inside the first .rc file, either:

    • Use the drag-and-drop method

      1. Select the resource you wish to copy. For example, in Source1.rc, select IDD_DIALOG1.

      2. Hold down the Ctrl key and drag the resource to the second .rc file. For example, drag IDD_DIALOG1 from Source1.rc to Source2.rc.

        Tip

        Dragging the resource without holding down the Ctrl key moves the resource rather than copying it.

    • Use the copy and paste method

      1. Right-click the resource you with to copy (for example, Source1.rc) and choose Copy.

      2. Right-click the resource file into which you'd like to paste the resource (for example, Source2.rc) and choose Paste.

Note

To avoid conflicts with symbol names or values in the existing file, Visual C++ may change the transferred resource's symbol value or symbol name and value when you copy it to the new file.

While copying in a resource, you can change its language property or condition property, or both.

  • The language of a resource specifies the language used by FindResource to help identify the resource for which you're looking. Resources can have differences for each language that aren't related to text, for example, accelerators that might only work on a Japanese keyboard or a bitmap that would only be appropriate for Chinese localized builds.

  • The condition of a resource is a defined symbol that identifies a condition under which this particular copy of the resource is to be used.

The language and condition of a resource are shown in parentheses after the name of the resource in the Workspace window. Here the resource named IDD_AboutBox is using Finnish as its language and its condition is XX33:

IDD_AboutBox (Finnish - XX33)

To copy an existing resource and change its language or condition

In the .rc file or in the Resource View window, right-click the resource you want to copy and choose Insert Copy. Then set the following:

  • For the Language list box, select the language.

  • In the Condition box, type the condition.

To edit resources

Managed resource (.resx) files are XML files. When you add a managed resource file to your project from the Add New Item dialog box, the Managed Resources Editor opens by default.

Import and Export Resources

You can import graphical resources (bitmaps, icons, cursors, and toolbars), HTML files, and custom resources for use in Visual C++. You can export the same types of files from a Visual Studio C++ project to separate files that can be used outside the development environment.

Note

Resource types such as accelerators, dialog boxes, and string tables can't be imported or exported because they're not stand-alone file types.

To import a resource into the resource script file

  1. In Resource View right-click the node of the resource script (.rc) file to which you want to add a resource and select Import.

  2. Locate and choose the file name of the bitmap (.bmp), icon (.ico), cursor (.cur), html file (.htm), or other file to import.

  3. Select OK to add the resource to the resource script file.

Note

The import process works the same no matter which resource type you have selected. The imported resource is automatically added to the correct node of that resource type.

To export a resource for use outside of Visual C++

  1. In Resource View, right-click the resource you want to export and select Export. You can accept the current file name or type a new one.

  2. Navigate to the folder where you want to save the file and select Export.

Requirements

Win32

See also

Resource Files
How to: Create Resources
How to: Include Resources at Compile Time