This function appends a new item to the end of the specified menu. You can use AppendMenu to specify the content, appearance, and behavior of the menu item.
At a Glance
Header file: | Winuser.h |
Windows CE versions: | 1.0 and later |
Syntax
BOOL AppendMenu(HMENU hMenu, UINT uFlags, UINT idNewItem,
LPCTSTR lpszNewItem);
Parameters
hMenu
[in] Handle to the menu bar, drop-down menu, submenu, or shortcut menu to be changed.
uFlags
[in] Specifies flags to control the appearance and behavior of the new menu item. This parameter can be a combination of the values listed in the following Remarks section.
uIDNewItem
[in] Specifies either the identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, the handle to the drop-down menu or submenu.
lpNewItem
[in] Long pointer to the content of the new menu item. The interpretation of lpNewItem depends on whether the uFlags parameter includes the MF_OWNERDRAW or MF_STRING flag, as follows:
Value | Description |
MF_OWNERDRAW | Contains a 32-bit value supplied by the application that can be used to maintain additional data related to the menu item. The value is in the itemData member of the structure pointed to by the lparam parameter of the WM_MEASURE or WM_DRAWITEM message sent when the menu is created or its appearance is updated. |
MF_STRING | Contains a pointer to a null-terminated string. |
Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
Remarks
The application must call the DrawMenuBar function whenever a menu changes, whether or not the menu is in a displayed window.
To get keyboard accelerators to work with bitmap or owner-drawn menu items, the owner of the menu must process the WM_MENUCHAR message.
The following flags can be set in the uFlags parameter:
MF_CHECKED
Places a check mark next to the menu item.
MF_ENABLED
Enables the menu item so it can be selected, and restores it from its grayed state.
MF_GRAYED
Disables the menu item and grays it so it cannot be selected.
MF_MENUBARBREAK
Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is separated from the old column by a vertical line.
Windows CE versions 1.0 and 1.01 do not support this flag.
MF_MENUBREAK
Places the item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu) without separating columns.
Windows CE versions 1.0 and 1.01 do not support this flag.
MF_OWNERDRAW
Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the window procedure of the owner window whenever the appearance of the menu item must be updated.
MF_POPUP
Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies the handle to the drop-down menu or submenu. This flag is used to add a menu name to a menu bar, or a menu item that opens a submenu to a drop-down menu, submenu, or shortcut menu.
Windows CE versions 1.0 and 1.01 do not support this flag.
MF_SEPARATOR
Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
MF_STRING
Specifies that the menu item is a text string; the lpNewItem parameter points to the string.
MF_UNCHECKED
Does not place a check mark next to the item (default).
The following groups of flags cannot be used together:
Windows CE version 1.0 does not support cascading menus. If you are using Windows CE version 1.0, you cannot insert an MF_POPUP menu into another pop-up menu. In Windows CE versions 2.0 and later, cascading menus are supported.
See Also