TN020: ID Naming and Numbering Conventions

This note describes the ID naming and numbering conventions used by MFC 2.0 for resources, commands, strings, controls, and child windows.

The Problem

The MFC ID naming and numbering conventions are intended to meet the following requirements:

Overview of ID Prefix Naming Convention

There are several categories or types of IDs in an application. The MFC ID-naming convention defines different prefixes for different resource types.

MFC uses the prefix "IDR_" to refer to a resource ID that applies to multiple resource types. For example, for a given frame window, the same "IDR_" value is used to refer to a menu, accelerator, string and icon resource all at once.

IDR_ Multiple resource types (Used for Menus, Accelerators primarily).
IDD_ For dialog template resources (for example, IDD_DIALOG1).

IDC_

For Cursor resources.

IDI_

For Icon resources.

IDB_

For Bitmap resources.

IDS_

For String resources.


Note that the IDS_ value for a string resource is the ID passed to LoadString. The actual implementation of string table resources groups together 16 strings into one segment.

Within a DIALOG resource, we follow the convention of:

IDOK,IDCANCEL For standard push button IDs.
IDC_

For other dialog controls.

The "IDC_" prefix is also used for cursors. This naming conflict is not usually a problem since a typical application will have few cursors and a large number of dialog controls.

Within a Menu resource, we follow the convention of:

IDM_ For menu items not using the MFC command architecture.
ID_

For menu item commands using the MFC command architecture.

Commands that follow the MFC command architecture must have an ON_COMMAND command handler and may have an ON_UPDATE_COMMAND_UI handler. If these command handlers follow the MFC command architecture, they will function correctly whether they are bound to a menu item, a toolbar button or a dialog bar button. The same ID_ is also used for a menu prompt string displayed on the program's message bar. Most of the menu items in your application should follow the MFC command convention. All of the standard command IDs (for example, ID_FILE_NEW) follow this convention.

MFC also uses "IDP_" as a specialized form of strings (that is, instead of "IDS_"). Strings with the "IDP_" prefix are "prompts," that is, strings used in message boxes. "IDP_" strings may contain "%1" and "%2" as place holders of strings determined by the program. "IDP_" strings usually have help topics, while "IDS_" strings do not. "IDP_" strings are always localized, while "IDS_" strings may or may not be localized.

The MFC library also uses the "IDW_" prefix as a specialized form of control IDs (that is, instead of "IDC_"). These IDs are assigned to child windows such as views and splitters by the framework classes. MFC implementation IDs are prefixed with "AFX_".

Overview of ID-Numbering Convention

The following lists the valid ranges for the IDs of the specific types. Some of the limits are technical implementation limits while others are just conventions to prevent your IDs from colliding with Windows predefined IDs or MFC default implementations.

We strongly recommend you do not defined IDs outside the recommended ranges. Even though the lower limit of many of these ranges is 1 (0 is not used), common convention starts practical use of IDs at 100 or 101.

Prefix Resource Type Valid Range
IDR_ multiple 1 -> 0x6FFF
IDD_ dialog templates 1 -> 0x6FFF
IDC_,IDI_,IDB_ cursors, icons, bitmaps 1 -> 0x6FFF
IDS_, IDP_ general strings 1 -> 0x7FFF
ID_ commands 0x8000 -> 0xDFFF
IDC_ controls 8 -> 0xDFFF

Reasons for these range limits:

Technical Notes by NumberTechnical Notes by Category