Creating, Displaying, and Destroying Menus

Most applications create menus using menu-template resources. A menu template defines a menu, including the items in the menu bar and all submenus. For information about creating a menu-template resource, see the documentation included with your development tools.

After you create a menu-template resource and add it to your application's executable (.exe) file, use the LoadMenu function to load the resource into memory. Implementing menus as resources makes an application easier to localize for use in multiple countries because only the resource-definition file needs to be localized for each language, not the application's source code.

Use the CreateMenu function to create an empty menu bar and the CreatePopupMenu function to create an empty menu. To add items to a menu, use the AppendMenu and InsertMenu functions.

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 still 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's 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.

For general guidelines on menu design, see Designing the User Interface for Windows CE.