The GetMenuState function retrieves the menu flags associated with the specified menu item. If the menu item opens a submenu, this function also returns the number of items in the submenu.
Syntax
UINT GetMenuState(
HMENU hMenu,
UINT uId,
UINT uFlags
);
Parameters
- hMenu
-
[in] Handle to the menu that contains the menu item whose flags are to be retrieved.
- uId
-
[in] Specifies the menu item for which the menu flags are to be retrieved, as determined by the uFlags parameter.
- uFlags
-
[in] Specifies how the uId parameter is interpreted. This parameter can be one of the following values.
MF_BYCOMMAND- Indicates that the uId parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
MF_BYPOSITION- Indicates that the uId parameter gives the zero-based relative position of the menu item.
Return Value
If the specified item does not exist, the return value is -1.
If the menu item opens a submenu, the low-order byte of the return value contains the menu flags associated with the item, and the high-order byte contains the number of items in the submenu opened by the item.
Otherwise, the return value is a mask (Bitwise OR) of the menu flags. Following are the menu flags associated with the menu item.
| MF_CHECKED | A check mark is placed next to the item (for drop-down menus, submenus, and shortcut menus only). |
| MF_DISABLED | The item is disabled. |
| MF_GRAYED | The item is disabled and grayed. |
| MF_HILITE | The item is highlighted. |
| MF_MENUBARBREAK | This is the same as the MF_MENUBREAK flag, except for drop-down menus, submenus, and shortcut menus, where the new column is separated from the old column by a vertical line. |
| MF_MENUBREAK | The item is placed on a new line (for menu bars) or in a new column (for drop-down menus, submenus, and shortcut menus) without separating columns. |
| MF_OWNERDRAW | The item is owner-drawn. |
| MF_POPUP | Menu item is a submenu. |
| MF_SEPARATOR | There is a horizontal dividing line (for drop-down menus, submenus, and shortcut menus only). |
Remarks
Note The
GetMenuState function has been superseded by the
GetMenuItemInfo. You can still use
GetMenuState, however, if you do not need any of the extended features of
GetMenuItemInfo.
In addition, it is possible to test an item for a flag value of MF_ENABLED, MF_STRING, MF_UNCHECKED, or MF_UNHILITE. However, since these values equate to zero you must use an expression to test for them.
| Flag | Expression to test for the flag |
|---|
| MF_ENABLED | ! (Flag&(MF_DISABLED | MF_GRAYED)) |
| MF_STRING | ! (Flag&(MF_BITMAP | MF_OWNERDRAW)) |
| MF_UNCHECKED | ! (Flag&MF_CHECKED) |
| MF_UNHILITE | ! (Flag&HILITE) |
Example
For an example, see Simulating Check Boxes in a Menu.
Function Information
| Minimum DLL Version | user32.dll |
|---|
| Header | Declared in Winuser.h, include Windows.h |
|---|
| Import library | User32.lib |
|---|
| Minimum operating systems |
Windows 95, Windows NT 3.1 |
|---|
See Also