Share via


Creating Menus (Windows CE 5.0)

Send Feedback

A menu is a list of options called menu items from which a user can choose to perform an action. Choosing a menu item opens a submenu or causes the application to execute a command. Virtually all main windows contain some type of menu. In many Windows CE–based applications, these menus are placed in a command bar, but you can also place a menu directly on the window itself. A command bar combines the features of a menu bar and a toolbar in one control. For more information about creating a command bar, see Creating Controls.

ms906589.menuce(en-us,MSDN.10).gif

In addition to standard menus and command bar menus, some Windows CE–based applications include scrolling menus. If a menu does not fit on the screen, Windows CE adds scroll arrows so that users can scroll up and down through the menu. When a user cannot scroll any further in one direction or the other, the associated scroll arrow is dimmed. An application dims unavailable items to provide a visual indicator that a selection is unavailable. Pressing the up or down scroll arrow scrolls through the menu one item at a time. No menu item is highlighted while scrolling. Changing the selection by using a keyboard arrow key or keyboard mnemonic causes the newly selected item to scroll into view, if it is not already displayed. If a menu has too many columns to fit the width of the display area, Windows CE ignores all column breaks and converts the menu into a single-column scrolling menu. If an individual menu item is too large to be drawn without being clipped by the up or down scroll arrow, the item is not drawn. This might leave a large blank space next to a scroll arrow.

Regardless of whether a menu is standard or scrolling, all menus in Windows CE are implemented as a top-level, pop-up window. A pop-up window menu is a floating menu that displays commands specific to the object selected by the user or to the object's immediate context. Each menu must have an owner window. Windows CE sends a WM_COMMAND message to a menu's owner window when the user selects the menu or chooses an item from the menu. When a user selects a menu item that opens a submenu, Windows CE does not send a command message to the menu's owner window. Rather, Windows CE sends a WM_INITMENUPOPUP message before displaying the submenu. Obtain the handle to the submenu associated with an item by using the GetSubMenu or GetMenuItemInfo function.

The following code example shows how to use GetSubMenu to obtain a handle to a submenu.

HWND hwndCB; // The command bar handle

// The "popup" menu item is at postion 4.
HMENU hmenuSubMenu = GetSubMenu(CommandBar_GetMenu(hwndCB, 0), 4);

There are two ways to create a menu: define a menu template in your resource file or use menu creation functions.

See Also

Using Resources | GWES Application Development

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.