Menu Items

Windows CE generates a unique handle for each menu. A menu handle is a value of the HMENU type. You must specify a menu handle in many of the Windows CE menu functions. To retrieve the handle to the submenu associated with a menu item, use the GetSubMenu or GetMenuItemInfo function.

In addition to having a unique handle, each menu item in a command bar or menu has a unique position value. The leftmost item in a command bar, or the top item in a menu, has position zero. The position value is incremented for subsequent menu items. Windows CE assigns a position value to all items in a menu, including separators. When calling a menu function that modifies or retrieves information about a specific menu item, specify the item using either its handle or its position.

A menu item can be either checked or unchecked. Windows CE displays a bitmap next to checked menu items to indicate their checked state; it does not display a bitmap next to unchecked items. Only menu items in a menu can be checked; items in a command bar cannot be checked.

Applications check or uncheck a menu item to indicate whether an option is in effect. For example, suppose an application has a toolbar that the user can show or hide by using a Toolbar command on a menu. When the toolbar is hidden, the Toolbar menu item is unchecked. When the user chooses the command, the application checks the menu item and shows the toolbar. A checkmark attribute controls whether a menu item is checked. Set a menu item's checkmark attribute by using the CheckMenuItem function.

Sometimes, a group of menu items corresponds to a set of mutually exclusive options. In this case, indicate the selected option by using a checked radio menu item — analogous to a radio button control. Checked radio items are displayed with a bullet bitmap instead of a check mark bitmap. To check a menu item and make it a radio item, use the CheckMenuRadioItem function.

When a menu item is not available to the user, the item should be grayed. Grayed menu items cannot be chosen. An application grays an unavailable menu item to provide a visual cue to the user that a command is not available. You can use a grayed item when an action is not appropriate. For example, you can gray the Print command in the File menu when the system does not have a printer installed.

A menu item can be enabled or grayed by using the EnableMenuItem function. To determine whether a menu item is enabled or grayed, use the GetMenuItemInfo function.