A menu template defines a menu, including all associated menu items and submenus, in a resource file. Implementing a menu as a resource makes an application easier to localize because only the resource-definition file needs to be localized for each language, and not the application source code. The following code example shows the syntax for menu resource definitions.
menuID MENU [[optional-statements]] { item-definitions . . . }
Here, menuID is either a unique string or unique 16-bit unsigned integer that identifies the menu, optional-statements specify options you can include when creating a menu, and item-definitions are used to create menu items.
There are two types of menu items you can create: MENUITEM and POPUP. A MENUITEM statement specifies a final selection; a POPUP statement specifies a popup submenu, which also may contain MENUITEM and POPUP statements. The following code example shows the syntax for these two menu items.
MENUITEM text, result, [[optionlist]] MENUITEM SEPARATOR
POPUP text, [[optionlist]] { item-definitions . . . }
Here, text is a string that contains the name of the menu, optionlist is a parameter that specifies the appearance of the menu, such as checked or dimmed, and result is the number that is generated when the user chooses the menu item. This parameter accepts an integer value and returns an integer; when the user selects the menu item name, the result is sent to the window that owns the menu.
Windows CE provides a special type of menu item, called a separator, that appears as a horizontal line. You can use a separator to divide a menu into groups of related items. The MENUITEM SEPARATOR form of the MENUITEM statement creates a separator. A separator cannot be used in a command bar, and the user cannot select a separator.
The following code example shows a complete MENU statement.
#define IDR_CEPADMENU 101
#define IDM_NEW 40001
#define IDM_OPEN 40002
#define IDM_SAVE 40003
#define IDM_SAVEAS 40004
#define IDM_EXIT 40005
#define IDM_ABOUT 40006
#define IDM_UNDO 40007
#define IDM_CUT 40008
#define IDM_COPY 40009
#define IDM_PASTE 40010
#define IDM_CLEAR 40011
#define IDM_SELECTALL 40012
#define IDM_FIND 40013
#define IDM_FINDNEXT 40014
#define IDM_REPLACE 40015
IDR_CEPADMENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New Ctrl+N", IDM_NEW
MENUITEM "&Open... Ctrl+O", IDM_OPEN
MENUITEM "&Save Ctrl+S" IDM_SAVE
MENUITEM "Save &As...", IDM_SAVEAS
MENUITEM SEPARATOR
MENUITEM "&Exit", IDM_EXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "&Undo Ctrl+Z", IDM_UNDO
MENUITEM SEPARATOR
MENUITEM "Cu&t Ctrl+X", IDM_CUT
MENUITEM "&Copy Ctrl+C", IDM_COPY
MENUITEM "&Paste Ctrl+V", IDM_PASTE
MENUITEM "Clea&r Del", IDM_CLEAR
MENUITEM SEPARATOR
MENUITEM "Select A&ll Ctrl+A", IDM_SELECTALL
END
POPUP "&Search"
BEGIN
MENUITEM "&Find... Ctrl+F", IDM_FIND
MENUITEM "Find &Next F3", IDM_FINDNEXT
MENUITEM "R&eplace... Ctrl+H", IDM_REPLACE
END
POPUP "&Help"
BEGIN
MENUITEM "&About CE Pad", IDM_ABOUT
END
END
Menu-template resources can be loaded explicitly or assigned as the default menu for a window class. To load a menu explicitly, call the LoadMenu function. To assign a menu to a window class, assign the name of the menu-template resource to the lpszMenuName member of the WNDCLASS structure that is used to register the class.