Several types of IDs can occur in an application. The MFC ID-naming convention defines different prefixes for different resource types.
MFC uses the prefix "IDR_" to indicate a resource ID that applies to multiple resource types. For example, for a given frame window, MFC uses the same "IDR_" prefix to indicate a menu, accelerator, string and icon resource. The following table shows the various prefixes and their usage:
Prefix | Use |
|---|
IDR_ | For multiple resource types (primarily used for menus and accelerators). |
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. |
Within a DIALOG resource, MFC follows these conventions:
Prefix or label | Use |
|---|
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 because a typical application will have few cursors and many dialog controls.
Within a menu resource, MFC follows these conventions:
Prefix | Use |
|---|
IDM_ | For menu items that do not use the MFC command architecture. |
ID_ | For menu commands that use the MFC command architecture. |
Commands that follow the MFC command architecture must have an ON_COMMAND command handler and can 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 command, a toolbar button, or a dialog bar button. The same "ID_" prefix is also used for a menu prompt string that is displayed on the program's message bar. Most of the menu items in your application should follow the MFC command conventions. All of the standard command IDs (for example, ID_FILE_NEW) follow this convention.
MFC also uses "IDP_" as a specialized form of strings (instead of "IDS_"). Strings with the "IDP_" prefix are prompts, that is, strings used in message boxes. "IDP_" strings can contain "%1" and "%2" as placeholders of strings determined by the program. "IDP_" strings usually have help topics associated with them, and "IDS_" strings do not. "IDP_" strings are always localized, and "IDS_" strings might not be localized.
The MFC library also uses the "IDW_" prefix as a specialized form of control IDs (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_".