BOOL ModifyMenu(hmenu, idItem, fuFlags, idNewItem, lpNewItem) | |||||
HMENU hmenu; | /* handle of menu, */ | ||||
UINT idItem; | /* menu-item identifier, */ | ||||
UINT fuFlags; | /* menu-item flags, */ | ||||
UINT idNewItem; | /* new menu-item identifier | */ | |||
LPCSTR lpNewItem; | /* menu-item content, */ |
The ModifyMenu function changes an existing menu item.
hmenu
Identifies the menu to change.
idItem
Specifies the menu item to change, as determined by the fuFlags parameter. When the fuFlags parameter is MF_BYCOMMAND, the idItem parameter specifies the menu-item identifier. When the fuFlags parameter is MF_BYPOSITION, the idItem parameter specifies the zero-based position of the menu item.
fuFlags
Specifies how the idItem parameter is interpreted and information about the changes to be made to the menu item. It consists of one or more values listed in the following Comments section.
idNewItem
Specifies either the identifier of the modified menu item or, if fuFlags is set to MF_POPUP, the menu handle of the pop-up menu.
lpNewItem
Specifies the content of the changed menu item. If fuFlags is set to MF_STRING (the default), lpNewItem is a long pointer to a null-terminated string. If fuFlags is set to MF_BITMAP instead, lpNewItem contains a bitmap handle in its low-order word. If fuFlags is set to MF_OWNERDRAW, lpNewItem specifies an application-defined 32-bit value that the application can use to maintain additional data associated with the menu item. This 32-bit value is available to the application in the itemData member of the MEASUREITEMSTRUCT or DRAWITEMSTRUCT structure pointed to by the lParam parameter of the WM_MEASUREITEM or WM_DRAWITEM message. These messages are sent when the menu item is initially displayed or is changed.
The return value is nonzero if the function is successful. Otherwise, it is zero.
If the ModifyMenu function replaces a pop-up menu associated with the menu item, it destroys the old pop-up menu and frees the memory used by the pop-up menu.
Whenever a menu changes (whether or not it is in a window that is displayed), the application should call DrawMenuBar. To change the attributes of existing menu items, it is much faster to use the CheckMenuItem and EnableMenuItem functions.
Each of the following groups lists flags that should not be used together:
MF_BYCOMMAND and MF_BYPOSITION
MF_DISABLED, MF_ENABLED, and MF_GRAYED
MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
MF_MENUBARBREAK and MF_MENUBREAK
MF_CHECKED and MF_UNCHECKED
The following list describes the flags that may be set in the fuFlags parameter:
Value | Meaning |
MF_BITMAP | Uses a bitmap as the menu item. The low-order word of the lpNewItem parameter contains the handle of the bitmap. |
MF_BYCOMMAND | Specifies that the idItem parameter gives the menu-item identifier. This is the default if neither MF_BYCOMMAND nor MF_POSITION is set. |
MF_BYPOSITION | Specifies that the idItem parameter gives the position of the menu item to be changed rather than the menu-item identifier. |
MF_CHECKED | Places a check mark next to the menu item. If the application has supplied check-mark bitmaps (see SetMenuItemBitmaps), setting this flag displays the check-mark bitmap next to the menu item. |
MF_DISABLED | Disables the menu item so that it cannot be selected, but does not gray (dim) it. |
MF_ENABLED | Enables the menu item so that it can be selected and restores it from its grayed state. |
MF_GRAYED | Disables the menu item so that it cannot be selected and grays it. |
MF_MENUBARBREAK | Same as MF_MENUBREAK except, for pop-up menus, separates the new column from the old column with a vertical line. |
MF_MENUBREAK | Places the menu item on a new line for static menu-bar items. For pop-up menus, this flag places the item in a new column, with no dividing line between the columns. |
MF_OWNERDRAW | Specifies that the menu item is an owner-drawn item. The window that owns the menu receives a WM_MEASUREITEM message when the menu is displayed for the first time to retrieve the height and width of the menu item. The WM_DRAWITEM message is then sent whenever the owner must update the visual appearance of the menu item. This option is not valid for a top-level menu item. |
MF_POPUP | Specifies that the item has a pop-up menu associated with it. The idNewItem parameter specifies a handle of a pop-up menu to be associated with the menu item. Use this flag for adding either a top-level pop-up menu or a hierarchical pop-up menu to a pop-up menu item. |
MF_SEPARATOR | Draws a horizontal dividing line. This line cannot be grayed, disabled, or highlighted. You can use this flag only in a pop-up menu. The lpNewItem and idNewItem parameters are ignored. |
MF_STRING | Specifies that the menu item is a character string; the lpNewItem parameter points to the string for the menu item. |
MF_UNCHECKED | Does not select (place a check mark next to) the menu item. No check mark is the default condition if neither MF_CHECKED nor MF_UNCHECKED is set. If the application has supplied check-mark bitmaps (see the SetMenuItemBitmaps function), setting this flag displays the “check mark off” bitmap next to the menu item. |
CheckMenuItem, DrawMenuBar, EnableMenuItem, SetMenuItemBitmaps