Creating a New Menu

You can create new menus while your application runs, using the CreateMenu function. CreateMenu creates a new, empty menu; you can then add items to it using AppendMenu or InsertMenu.

The following example creates an empty pop-up menu and appends it to the window's menu. It then appends three items to the new pop-up menu.

HMENU hWinMenu;

HMENU hVeggieMenu;

.

.

.

hVeggieMenu = CreateMenu ();

AppendMenu (hWinMenu,

MF_POPUP | MF_ENABLED,

hVeggieMenu,

“Veggies”);

AppendMenu (hVeggieMenu,

MF_ENABLED,

IDM_CELERY,

“Celery”);

AppendMenu (hVeggieMenu,

MF_ENABLED,

IDM_LETTUCE,

“Lettuce”);

AppendMenu (hVeggieMenu,

MF_ENABLED,

IDM_PEAS,

“Peas”);