BOOL EnableMenuItem(hmenu, idEnableItem, uEnable) | ||||
HMENU hmenu; | /* handle of menu, */ | |||
UINT idEnableItem; | /* menu-item identifier, */ | |||
UINT uEnable; | /* action flag, */ |
The EnableMenuItem function enables, disables, or grays (dims) a menu item.
hmenu
Identifies the menu.
idEnableItem
Specifies the menu item to be enabled, disabled, or grayed. This parameter can specify pop-up menu items as well as standard menu items. The interpretation of this parameter depends on the value of the uEnable parameter.
uEnable
Specifies the action to take. This parameter can be MF_DISABLED, MF_ENABLED, or MF_GRAYED, combined with MF_BYCOMMAND or MF_BYPOSITION. These values have the following meanings:
Value | Meaning |
MF_BYCOMMAND | Specifies that the idEnableItem parameter gives the menu-item identifier. |
MF_BYPOSITION | Specifies that the idEnableItem parameter gives the position of the menu item (the first item is at position zero). |
MF_DISABLED | Specifies that the menu item is disabled. |
MF_ENABLED | Specifies that the menu item is enabled. |
MF_GRAYED | Specifies that the menu item is grayed. |
The return value is 0 if the menu item was previously disabled, 1 if the menu item was previously enabled, and –1 if the menu item does not exist.
To disable or enable input to a menu bar, see the WM_SYSCOMMAND message.
The CreateMenu, InsertMenu, ModifyMenu, and LoadMenuIndirect functions can also set the state (enabled, disabled, or grayed) of a menu item.
Using the MF_BYPOSITION value requires an application to specify the correct menu handle. If the menu handle of the menu bar is specified, a top-level menu item (an item in the menu bar) is affected. To set the state of an item in a pop-up or nested pop-up menu by position, an application must specify the handle of the pop-up menu.
When an application specifies the MF_BYCOMMAND flag, Windows checks all pop-up menu items that are subordinate to the menu identified by the specified menu handle; therefore, unless duplicate menu items are present, specifying the menu handle of the menu bar is sufficient.