UINT GetMenuState(hmenu, idItem, fuFlags) | ||||
HMENU hmenu; | /* handle of menu, */ | |||
UINT idItem; | /* menu-item identifier, */ | |||
UINT fuFlags; | /* menu flags, */ |
The GetMenuState function retrieves the status flags associated with the specified menu item. If the menu item is a pop-up menu, this function also returns the number of items in the pop-up menu.
hmenu
Identifies the menu.
idItem
Specifies the menu item for which the state is retrieved, as determined by the fuFlags parameter.
fuFlags
Specifies the nature of the idItem parameter. It can be one of the following values:
Value | Meaning |
MF_BYCOMMAND | Specifies the menu-item identifier. |
MF_BYPOSITION | Specifies the zero-based position of the menu item. |
The return value is –1 if the specified item does not exist. If the idItem parameter identifies a pop-up menu, the high-order byte of the return value contains the number of items in the pop-up menu, and the low order byte contains the menu flags associated with the pop-up menu. Otherwise, the return value is a mask (Boolean OR) of the values from the following list (this mask describes the status of the menu item that idItem identifies):
Value | Meaning |
MF_BITMAP | Item is a bitmap. |
MF_CHECKED | Check mark is placed next to item (pop-up menus only). |
MF_DISABLED | Item is disabled. |
MF_ENABLED | Item is enabled. Note that the value of this constant is zero; an application should not test against zero for failure when using this value. |
MF_GRAYED | Item is disabled and grayed. |
MF_MENUBARBREAK | Same as MF_MENUBREAK, except for pop-up menus where the new column is separated from the old column by a vertical dividing line. |
MF_MENUBREAK | Item is placed on a new line (static menus) or in a new column (pop-up menus) without separating columns. |
MF_SEPARATOR | Horizontal dividing line is drawn (pop-up menus only). This line cannot be enabled, checked, grayed, or highlighted. The idItem and fuFlags parameters are ignored. |
MF_UNCHECKED | Check mark is not placed next to item (default). Note that the value of this constant is zero; an application should not test against zero for failure when using this value. |
The following example retrieves the handle of a pop-up menu, retrieves the checked state of a menu item in the menu, and then toggles the checked state of the item:
HMENU hmenu;
BOOL fOwnerDraw;
/* Retrieve a handle to the Colors menu. */
hmenu = GetSubMenu(GetMenu(hwnd), ID_COLORS_POS);
/* Retrieve the current state of the item. */
fOwnerDraw = GetMenuState(hmenu, IDM_COLOROWNERDR,
MF_BYCOMMAND) & MF_CHECKED;
/* Toggle the state of the item. */
CheckMenuItem(hmenu, IDM_COLOROWNERDR,
MF_BYCOMMAND | (fOwnerDraw ? MF_UNCHECKED : MF_CHECKED));