Overview
The MENU resource defines a menu template that can be compiled into a binary resource and loaded by an application at runtime. Menus are described using a simple text‑based syntax in a .rc file and are typically built with the rc.exe resource compiler.
Syntax
The basic grammar for a MENU resource is:
MENU [MENU_ID] [options]
BEGIN
MENUITEM "Caption", [ID], [options]
POPUP "SubMenu Caption", [options]
BEGIN
MENUITEM "SubItem", [ID], [options]
...
END
...
END
Key elements:
- MENU_ID – numeric identifier or symbolic constant used with
LoadMenu. - MENUITEM – defines a selectable item. Use
MF_STRING,MF_DISABLED, etc., as options. - POPUP – defines a submenu container.
- BEGIN/END – delimit the scope of the menu or submenu.
Example
A simple menu resource definition:
#define IDR_MAINMENU 101
#define IDM_FILE_NEW 40001
#define IDM_FILE_OPEN 40002
#define IDM_HELP_ABOUT 40003
MENU IDR_MAINMENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New\tCtrl+N", IDM_FILE_NEW, MF_STRING
MENUITEM "&Open...\tCtrl+O", IDM_FILE_OPEN, MF_STRING
MENUITEM SEPARATOR
MENUITEM "E&xit", 0, MF_STRING
END
POPUP "&Help"
BEGIN
MENUITEM "&About...", IDM_HELP_ABOUT, MF_STRING
END
END
Remarks
- Use the ampersand (
&) before a character to designate a mnemonic. - Accelerator keys (e.g.,
\tCtrl+N) are optional and displayed in the menu. - Menu IDs are passed to the
WM_COMMANDmessage when a user selects an item. - The
SEPARATORkeyword inserts a horizontal line. - Resources can be loaded using
LoadMenuor attached to a window withSetMenu.