Changes an existing menu item at the position specified by nPosition.

BOOL ModifyMenu( 
   UINT nPosition, 
   UINT nFlags, 
   UINT_PTR nIDNewItem = 0, 
   LPCTSTR lpszNewItem = NULL  
BOOL ModifyMenu( 
   UINT nPosition, 
   UINT nFlags, 
   UINT_PTR nIDNewItem, 
   const CBitmap* pBmp  


Specifies the menu item to be changed. The nFlags parameter can be used to interpret nPosition in the following ways:


Interpretation of nPosition


Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set.


Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.


Specifies how nPosition is interpreted and gives information about the changes to be made to the menu item. For a list of flags that may be set, see the AppendMenu member function.


Specifies either the command ID of the modified menu item or, if nFlags is set to MF_POPUP, the menu handle (HMENU) of a pop-up menu. The nIDNewItem parameter is ignored (not needed) if nFlags is set to MF_SEPARATOR.


Specifies the content of the new menu item. The nFlags parameter can be used to interpret lpszNewItem in the following ways:


Interpretation of lpszNewItem


Contains an application-supplied 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 when it processes MF_MEASUREITEM and MF_DRAWITEM.


Contains a long pointer to a null-terminated string or to a CString.


The lpszNewItem parameter is ignored (not needed).


Points to a CBitmap object that will be used as the menu item.

Nonzero if the function is successful; otherwise 0.

The application specifies the new state of the menu item by setting values in nFlags. If this 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.

When nIDNewItem specifies a pop-up menu, it becomes part of the menu in which it is inserted. If that menu is destroyed, the inserted menu will also be destroyed. An inserted menu should be detached from a CMenu object to avoid conflict.

Whenever a menu that resides in a window is changed (whether or not the window is displayed), the application should call CWnd::DrawMenuBar. To change the attributes of existing menu items, it is much faster to use the CheckMenuItem and EnableMenuItem member functions.

See the example for CMenu::InsertMenu.

Header: afxwin.h

Community Additions