Using Menu Creation Functions

You use menu creation functions when you want to create or change a menu at run time. To create an empty menu bar, use the CreateMenu function; to create an empty menu, use the CreatePopupMenu function. To add items to a menu, use the AppendMenu and InsertMenu functions.

When a menu contains more items than will fit in one column, the menu is truncated unless you force a line break. You can cause a column break to occur at a specific item in a menu by assigning the MFT_MENUBREAK menu item type flag to the item. Windows CE places that item and all subsequent items in a new column. You can also assign the MFT_MENUBARBREAK menu item type flag to the item, which has the same effect as the MFT_MENUBREAK menu item type flag except that a vertical line appears between the new and existing columns.

To display a shortcut menu, use the TrackPopupMenuEx function. Shortcut menus, also called floating pop-up menus or context menus, are typically displayed when the WM_CONTEXTMENU message is processed. The older TrackPopupMenu function is supported, but new applications should use the TrackPopupMenuEx function.

If a menu is assigned to a window and that window is destroyed, Windows CE automatically destroys the menu, freeing the menu handle and the memory occupied by the menu. Windows CE does not automatically destroy a menu that is not assigned to a window. An application must destroy the unassigned menu by calling the DestroyMenu function.