Resource Editor Add-in

The Resource Editor add-in adds the capability to work with resource files (.res) within the Visual Basic integrated development environment. Resource files are compiled automatically by the Resource Editor, so you don’t need a separate resource compiler or .rc files.

You can use the Resource Editor to:

  • Add a resource file (.res) to your project

  • Add new string table, cursor, bitmap, icon, or custom resources to a resource file.

  • Edit the properties of resources within a resource file.

  • Delete resources from a resource file.

For More Information To learn more about resource files and how they can be used in a project, see "Working with Resource Files" in the Visual Basic Programmer’s Guide.


Topic Not Found

No matching topic was found. Some possible reasons and remedies are as follows:

  • The file (.chm) that contains the destination topic is not in the expected location.

    Remedy: Rerun the MSDN Library Setup.

  • The file (.chm) that contains the current topic or destination topic is out-of-date and the link is no longer valid.

    Remedy: Install the latest version of the MSDN Library.

  • The MSDN Library CD is not in the CD-ROM drive.

    Remedy: Insert the MSDN Library CD into the CD-ROM drive.


Bitmap Resources

A bitmap resource is a bitmap image file (.bmp) stored within a resource file. Each bitmap resource is identified by a unique index or resource ID. Bitmaps are extracted from a resource file at run-time using the LoadResPicture function, which takes the index and the format (0 or vbResBitmap) as arguments.

Bitmap resources provide a convenient way to store multiple images for an application while keeping the source files hidden from the user. You can use the Windows Paint application to edit or create bitmap files.


Cursor Resources

A cursor resource is a cursor file (.cur) stored within a resource file. Each cursor resource is identified by a unique index or resource ID. Cursors are extracted from a resource file at run-time using the LoadResPicture function, which takes the index and the format (2 or vbResCursor) as arguments.

Cursor resources provide a convenient way to store custom cursors for an application while keeping the source files hidden from the user. You can use the Image Edit application (available from the Tools directory of the Visual Basic CD) to edit or create cursors.


Custom Resources

A custom resource is used to store most any type of binary data within a resource file. Each custom resource is identified by a unique index or resource ID. Custom resources are extracted from a resource file at run-time using the LoadResData function which takes the index and the format as arguments. For custom resources created using the Resource Editor, the format is the same as the resource type that is entered in the Edit Properties dialog box. The format string must be enclosed in double quotation marks.

When using custom resources, it is necessary to add the code to your application to read and display the data contained in the file. This usually requires the use of Windows API calls. Common data types that might be stored as custom resources are sound (.wav) and video (.avi) files.

Custom resources provide a convenient way to store custom data for an application while keeping the source files hidden from the user.


Deleting a Resource File

Resource files may not be deleted directly from the Resource Editor. To remove a resource file from your project, select it in the Project Explorer and choose the Remove filename command from the Project menu.

You can use the Delete toolbar button on the Resource Editor toolbar to delete individual resources from a resource file.


Editing a Resource File

Resources within a resource file (.res) are added, deleted, and edited in the Resource Editor window. The techniques are basically the same for all resource types; some aspects of string table resources are handled differently.

To add a cursor, bitmap, icon, or custom resource, click the appropriate toolbar button on the Resource Editor toolbar. A File Open dialog box will open, allowing you to select an existing resource. The new resource will be assigned the next available resource ID for that resource type and a language ID based on the system LCID of your computer. Custom resources will be added with their type listed as "Custom".

To add a new string table resource, click the Edit String Table toolbar button. A resource files can only contain one string table resource which can contain multiple string tables. You can add additional string tables to an existing string table resource, or you can delete the existing string table resource and start a new one.

To edit a resource entry, select it in the Resource Editor tree view and click the Edit Properties toolbar button. This will display the Edit Properties dialog box, where you can edit the language ID for all resource types, the Resource ID for any type except string table resources, and the type name for custom resources. String table resources are edited in the String Table Editor. The Edit Properties dialog box also shows a thumbnail preview of bitmaps, cursors, and icons.

To add a duplicate cursor, bitmap, icon, or custom resource, select the resource to be duplicated and click the Duplicate toolbar button. A new copy of the resource will be added with the next available resource ID for that resource type.

To delete a resource of any type, click the Delete toolbar button.

Note The Resource Editor will not allow entry of resource IDs greater than 32767. This is due to a limitation of the LoadResource functions in Visual Basic. Resources created in another editor may have resource IDs as high as 65535. You can open these files in the Resource Editor, however you will not be able to edit any resource with an ID greater than 32767.


Editing a String Table

Strings and string tables are added, edited, and deleted from a string table resource in the String Table Editor, available from the Edit String Tables toolbar button on the Resource Editor toolbar.

To add a new string table, click the Insert New String Table toolbar button. A new string table will be added to the grid with the Language ID list box highlighted. You can choose the appropriate language ID from the list.

If this is the first string table in the resource, an initial entry is added to the grid with a resource ID of 101. If this is an additional string table, grid cells will be added for all existing rows.

To edit a resource ID or string entry, double-click a grid cell, or select a cell and begin typing. You can also select a range of cells and use the Cut, Copy, and Paste toolbar buttons to move or copy a group of strings.

To enter a carriage return or linefeed in a string entry, use CTRL+TAB for a carriage return and the CTRL+ENTER for a linefeed.

To add a new row to the grid, select the Insert New Row toolbar button, or press the ENTER key from the last row of the grid. To delete a row, select any cell in the row and choose the Delete Row toolbar button.

To delete an entire string table, select any cell in the column and click the Delete String Table button.

You can also renumber a contiguous group of resource ID's by selecting them and clicking the Renumber Rows toolbar button.

Note When sharing resource files for multilingual development, be careful not to edit entries created on another system. If a string entry was created on a system with a different LCID and character set, some string characters may show up as non-printing characters (rectangular blocks). Attempting to edit such a string may corrupt the file.


Icon Resources

An icon resource is an icon file (.ico) stored within a resource file. Each icon resource is identified by a unique index or resource ID. Icons are extracted from a resource file at run-time using the LoadResPicture function which takes the index and the format (1 or vbResIcon) as arguments.

Icon resources provide a convenient way to store multiple icons for an application while keeping the source files hidden from the user. You can use the Image Edit application (available from the Tools directory of the Visual Basic CD) to edit or create icons.


Loading or Unloading the Resource Editor

The Resource Editor add-in is loaded from the Add-In Manager dialog box, available from the Add-Ins menu. You can load the Resource Editor by selecting Resource Editor in the Available Add-Ins list and selecting the Loaded/Unloaded check box; you can unload it by clearing the check box. When you select the Resource Editor add-in, it is loaded every time you restart Visual Basic until you clear the check box.

When the Resource Editor is loaded, it adds a Resource Editor button to the Standard toolbar. It also adds two new menu commands: Add New Resource File on the Project menu, and Resource Editor on the Tools menu.


Multiple String Table Model

Resource files created with the Resource Editor can contain multiple string tables, each containing strings localized for a different language. A string table will automatically be selected at run-time based on the LCID of the system; if a match isn’t found the system will load the first string table in the resource file. This model is advantageous for creating an application which will be distributed for two or more languages with no requirement for multi-language support within a single instance.


Opening a Resource File

An existing resource file (.res) can be opened for editing in the Resource Editor by choosing Add New Resource File from the Project menu, or by clicking the Open Resource File toolbar button on the Resource Editor toolbar. The selected resource file will be added to the current project in the Project Explorer.

A new resource file can be created by clicking the New Resource File toolbar button on the Resource Editor toolbar. It will not appear in the Project Explorer until it has been saved.


Renumbering Resource Id's

Sometimes you may find it necessary to renumber some of the resource IDs for strings in a string table resource. For example, you may have grouped all strings for a particular form by numbering them 1–25. If you now find that you need 26 or more strings, you may want to move them to a larger block of numbers. The Renumber Resource dialog box, available from the Renumber Rows toolbar button, allows you to do this.

There are two options for renumbering resource IDs:

  • The Renumber Id’s option will renumber sequentially from the base value. For example, 101, 102, 106 would become 1001, 1002, 1003 (with a base value of 1000).

  • The Rebase Id’s option will renumber from the base value and maintain the existing offset. For example, 101, 102, 106 would become 1001, 1002, 1006 (with a base value of 1000).


Renumber Resource Id's Dialog Box

Use the Renumber Resource Id’s dialog box to change a selected block of resource IDs in a string table. Resource IDs can be renumbered sequentially, or by an offset from a base number.

You can open the Renumber Resource Id’s dialog box by clicking the Renumber Rows toolbar button when two or more resource ID’s are selected in the String Table editor.

Toolbar Shortcut:

Dialog Box Elements

Renumber Id’s

Renumbers the selected resource IDs sequentially.

Rebase Id’s

Renumbers the selected resource IDs using an offset.

Base Value

Specifies the new starting number.


Resource File Basics

Resource files are useful for localizing a Visual Basic application because multiple resources for multiple languages are isolated in a single file, eliminating the need to recompile the application for each language. A Visual Basic resource file (.res) can contain five different types of resources:

String Table resources

Cursor resources

Icon resources

Bitmap resources

Custom resources

For More Information To learn more about localizing applications, see "International Issues" in the Visual Basic Programmer’s Guide.


Single String Table Model

Most resource files contain a single string table and use an offset in the resource ID to create sets of strings for each language. At run-time the offset is used to load the appropriate strings. The Atm sample application included with Visual Basic is an example of the single string model.

Using this model, the offset can be set programmatically by reading the system locale ID (LCID) at startup, or by allowing the user to choose a language at run-time. If you want your application to be able to display multiple languages within a single application, you must use the single string table model.


Starting the Resource Editor

The Resource Editor add-in can be started in three different ways:

  • From the Project window, by double-clicking on a resource file, or by selecting a resource file and pressing the ENTER key.

  • From the Tools menu, by clicking the Resource Editor command.

  • From the Resource Editor toolbar button on the Visual Basic Standard toolbar.

Note The Resource Editor check box must be loaded in the Add-In Manager dialog box in order for the Resource Editor to be visible.


String Table Resources

A string table resource is a collection of strings that are stored within a resource file. Each string within a string table is identified by a unique index or resource ID. Strings are extracted from a resource file at run time using the LoadResString function, which takes the index as an argument.

Resource files created using the Resource Editor can contain multiple string table resources; resource files compiled using a traditional resource compiler can contain only a single string table. When creating resource files for localization, care should be taken in choosing the appropriate model for your application.

Single String Table Model

Multiple String Table Model


Updating a Resource File

Changes made to a resource file are not immediately reflected in your project. The file must be saved before your changes will be reflected. If you run your project before saving the resource file, any resources added to the file since the last save will not be loaded.

To save a resource file, click the Save toolbar button on the Resource Editor toolbar, or choose Save or Save As from the shortcut menu.

When a resource file has been changed but not saved, the status bar displays a File Modified icon and a Modified message as a reminder.


Add New Resource File Command (Project Menu)

Displays the Open A Resource File dialog box so you can insert an existing resource file (.res) into your active project. Each project can contain only one resource file. If a project already contains a resource file it will be replaced with the selection.

The Add New Resource File command is only visible when the Resource Editor add-in is loaded.

Note A resource file can also be added to a Project using the Add File command on the Project Menu.


Resource Editor Command (Tools Menu)

Displays the Resource Editor add-in, which displays a hierarchical list of resources contained in the resource file (.res) for the currently selected project. Resources can be added, deleted, or edited. If there is no resource file in the currently selected project, the Resource Editor displays a blank resource file.

The Resource Editor command is only visible when the Resource Editor add-in is loaded.

Toolbar shortcut:


Properties Dialog Box (Resource Editor Add-in)

Use the Properties dialog box to edit resource properties in a resource file (.res) associated with your project. The properties that may be edited are dependent on the resource type. The language ID may be edited for all resource types, the resource ID may be edited for all types except string table resources, and the type property may be edited for custom resources.

You can open the Properties dialog box by clicking the Edit Properties toolbar button when a resource is selected in the list window.

Toolbar shortcut:

Dialog Box Elements

ID

Contains the resource ID for the selected resource.

Language

Contains a drop-down list of language IDs for the selected resource.

Preview

Displays an image of the selected resource (bitmap, icon, and cursor resources only).

Type

Contains the type name for the selected custom resource.


Resource Editor Toolbar (Resource Editor Add-in)

The toolbar has buttons that act as shortcuts for various operations of the Resource Editor add-in. Pausing the mouse pointer over a button will display a description of that button. Clicking a button will cause the associated operation to occur.

The Resource Editor toolbar buttons are:

Button | Description
 | Adds a new resource file, replacing the current file
 | Displays the Open A Resource File dialog box
 | Saves the current resource file and updates the copy in the current project
 | Opens the Properties dialog box for the currently selected resource
 | Duplicates the selected resource and assigns the next available resource ID
 | Undoes the last operation
 | Deletes the selected resource
 | Opens the String Table Editor
 | Opens the Add Cursor dialog box
 | Opens the Add Icon dialog box
 | Opens the Add Bitmap dialog box
 | Opens the Add Custom Resource dialog box
 | Displays Resource Editor Help


Resource Editor Window (Resource Editor Add-in)

Use the Resource Editor window to add, delete, and edit resources in a resource file (.res) associated with your project. Only a single resource file may be edited at a time; a project can contain only a single resource file.

The Resource Editor window is dockable.

You can open the Resource Editor window from:

  • The Project window, by double-clicking on a resource file, or by selecting a resource file and pressing the ENTER key.

  • The Tools menu, by selecting the Resource Editor command.

  • The Resource Editor toolbar button on the Visual Basic Standard toolbar.

Note The Resource Editor add-in must be selected in the Add-In Manager dialog box in order for the Resource Editor to be visible.

Window Elements

List Window

Displays a hierarchical list of resource types and individual resources contained in the selected resource file.

Toolbar

Contains buttons representing shortcuts for various operations of the Resource Editor.

Status Bar

Displays an icon and a message to indicate that the file has been changed but not saved.


String Table Editor Toolbar

The toolbar has buttons that act as shortcuts for various operations of the String Table Editor. Pausing the mouse pointer over a button will display a description of that button. Clicking a button will cause the associated operation to occur.

The String Table Editor toolbar buttons are:

Button | Description
 | Inserts a new row at the bottom of the string table.
 | Inserts a new string table (column)
 | Displays the language selection list box for the selected string table
 | Opens the Renumber Resource Id’s dialog box
 | Cuts the selected text
 | Copies the selected text
 | Pastes text into the string table
 | Undoes the last operation
 | Deletes the selected row
 | Deletes the selected string table
 | Displays String Table Editor Help


String Table Editor Window (Resource Editor Add-in)

Use the String Table Editor window to add, delete, and edit string table resources in a resource file (.res) associated with your project.

You can open the String Table Editor window from:

  • The Edit String Tables button on the Resource Editor toolbar.

  • The list window, by double-clicking a String Table resource.

Window Elements

Toolbar

Contains buttons representing shortcuts for various operations of the String Table Editor.

String Table Grid

Displays resource IDs and string resources for all string tables in a resource file.