Changing Existing Menus

You can change existing menus and menu items by using the ModifyMenu function. For example, you might need to change the text of a menu item. ModifyMenu lets you enable, disable, gray, check, or uncheck the item.

In the following example, the ModifyMenu function changes the text of the Water command to Wine. The example also changes the item's menu ID.

ModifyMenu (hMenu,

IDM_WATER,

MF_BYCOMMAND,

IDM_WINE,

“Wine”);

When you use ModifyMenu, you are essentially telling Windows to replace a specific menu item with a new item. The third, fourth and fifth ModifyMenu parameters specify the attributes of the new item.

For example, the following statement changes the item text from Wine to Cabernet. Although only the menu item's text is changing, the statement nonetheless respecifies all the attributes of the item (in this case, just the menu ID).

ModifyMenu (hMenu,

IDM_WINE,

MF_BYCOMMAND,

IDM_WINE,

“Cabernet”);

Performing Several Changes at Once

When you use ModifyMenu to change a menu item, you can also check or
uncheck the item, and can enable, disable, or gray it as well.

The following example not only changes the Water command to Wine; it enables the command (if not already enabled), checks it, and changes its menu ID.

ModifyMenu (hMenu,

IDM_WATER,

MF_BYCOMMAND | MF_ENABLED | MF_CHECKED,

IDM_WINE,

“Wine”);