HMENU CreateMenu(void) |
The CreateMenu function creates a menu. The menu is initially empty but can be filled with menu items by using the AppendMenu or InsertMenu function.
This function has no parameters.
The return value is the handle of the newly created menu if the function is successful. Otherwise, it is NULL.
If the menu is not assigned to a window, an application must free system resources associated with the menu before exiting. An application frees menu resources by calling the DestroyMenu function. Windows automatically frees resources associated with a menu that is assigned to a window.
The following example creates a main menu and a pop-up menu and associates the pop-up menu with an item in the main menu:
HMENU hmenu;
HMENU hmenuPopup;
/* Create the main and pop-up menu handles. */
hmenu = CreateMenu();
hmenuPopup = CreatePopupMenu();
/* Create the pop-up menu items. *./
AppendMenu(hmenuPopup, MF_ENABLED | MF_STRING, IDM_NEW,
"&New");
AppendMenu(hmenuPopup, MF_ENABLED | MF_STRING, IDM_SAVE,
"&Save");
AppendMenu(hmenuPopup, MF_ENABLED | MF_STRING, IDM_SAVE_AS,
"&Save As");
/* Add the pop-up menu to the main menu. */
AppendMenu(hmenu, MF_ENABLED | MF_POPUP, (UINT) hmenuPopup,
"&File");