Share via


Setting Menu Item Attributes (Windows CE 5.0)

Send Feedback

Menu items possess attributes that affect their appearance. For example, a menu item can be checked or unchecked, mutually exclusive, or dimmed. You can change other menu attributes as well by creating an owner-drawn menu item. 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 menu items, including separators. When calling a menu function that modifies or retrieves information about a specific menu item, specify the item by using either its handle or its position.

A check mark attribute controls whether a menu item is checked. Applications check or uncheck a menu item to indicate whether an option is in effect. For example, suppose that an application has a toolbar that a user can hide or display 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. 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 appearing in a command bar cannot be checked. To set a menu item check mark attribute, call the CheckMenuItem function.

The following code example shows how to use CheckMenuItem to change the state of the check mark attribute.

if (fTrack) {
  CheckMenuItem(hmenuSubMenu, ID_POPUP_TRACK, 
                MF_BYCOMMAND | MF_UNCHECKED);
  fTrack = FALSE;
}
else {
  CheckMenuItem(hmenuSubMenu, ID_POPUP_TRACK, MF_BYCOMMAND | MF_CHECKED);
  fTrack = TRUE;
}

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.

The following code example shows how to use the CheckMenuRadioItem function.

CheckMenuRadioItem(hmenuSubMenu, ID_POPUP_ENABLE, ID_POPUP_DISABLE, 
                   ID_POPUP_ENABLE, MF_BYCOMMAND);

Another menu item attribute you can change is whether or not a menu item is enabled. When a menu item is not available, the item should be dimmed. Dimmed menu items cannot be chosen. You can use a dimmed item when an action is not appropriate. For example, you can dim the Print command on the File menu when the system does not have a printer installed. A menu item can be enabled or dimmed by using the EnableMenuItem function. To determine whether a menu item is enabled or dimmed, use the GetMenuItemInfo function.

The following code example shows how to use the EnableMenuItem function to enable a menu item.

EnableMenuItem(hmenuSubMenu, ID_POPUP_TRACK, MF_BYCOMMAND | MF_ENABLED);

You can control a menu item's appearance by using an owner-drawn item. Owner-drawn items require an application to draw selected, checked, and unchecked states. For example, if an application provides a font menu, it can draw each menu item by using the corresponding font; the item for Roman will be drawn in Roman, the item for Italic will be drawn in Italic, and so on.

Windows CE handles owner-drawn menu items differently from Windows-based desktop platforms. In some respects, it treats an owner-drawn item as any other menu item. On other Windows-based platforms, the device context is initialized to its default state. On Windows CE, the device context is initialized to the dimmed or highlighted status of the current item. Also, unlike other Windows-based platforms, Windows CE automatically highlights an owner-drawn menu item when it has the keyboard focus.

See Also

Creating Menus | Using Resources | GWES Application Development

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.