CMenu
From Win32++
|
CMenu Class |
Description
CMenu adds support for menus to Win32++. A menu is a list of items that specify options or groups of options (a submenu) for an application. Clicking a menu item opens a submenu or causes the application to carry out a command.
A menu is arranged in a hierarchy. At the top level of the hierarchy is the menu bar which contains a list of menus, which in turn can contain submenus. A menu bar is sometimes called a top-level menu, and the and submenus are also known as pop-up menus.
A menu item can either carry out a command or open a submenu. An item that carries out a command is called a command item or a command.
CMenu Members
| Initialisation and Assignment | |
| CMenu | CMenu(); CMenu(UINT nID);Constructor for CMenu. |
void Attach(HMENU hMenu);Attaches an existing menu to this CMenu. CreateMenu
void CreateMenu();Creates an empty menu. CreatePopupMenu
void CreatePopupMenu();Creates a drop-down menu, submenu, or shortcut menu. The menu is initially empty.. DestroyMenu
void DestroyMenu();Destroys the menu. Detach
HMENU Detach();Detaches the HMENU from this CMenu. If the HMENU is not detached it will be destroyed when this CMenu is deconstructed. FromHandle
static CMenu* FromHandle(HMENU hMenu);Returns the CMenu associated with the specified menu handle. If a CMenu object doesn't already exist, a temporary CMenu object is created. This temporary CMenu will be deleted sometime after the processing of the current message is complete. GetHandle
HMENU GetHandle() const;Returns the HMENU assigned to this CMenu. LoadMenu
BOOL LoadMenu(LPCTSTR lpszResourceName);
BOOL LoadMenu(UINT uIDResource);
BOOL LoadMenuIndirect(const void* lpMenuTemplate);Loads the menu from the specified windows resource or template. TrackPopupMenu
BOOL TrackPopupMenu(UINT uFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = 0);Displays a shortcut menu at the specified location and tracks the selection of items on the menu.. TrackPopupMenuEx
BOOL TrackPopupMenuEx(UINT uFlags, int x, int y, CWnd* pWnd, LPTPMPARAMS lptpm);Displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. Menu Item Operations AppendMenu
BOOL AppendMenu(UINT uFlags, UINT_PTR uIDNewItem = 0, LPCTSTR lpszNewItem = NULL);
BOOL AppendMenu(UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp);Appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu. CheckMenuItem
UINT CheckMenuItem(UINT uIDCheckItem, UINT uCheck);Sets the state of the specified menu item's check-mark attribute to either selected or clear. CheckMenuRadioItem
BOOL CheckMenuRadioItem(UINT uIDFirst, UINT uIDLast, UINT uIDItem, UINT uFlags);Checks a specified menu item and makes it a radio item. At the same time, the function clears all other menu items in the associated group and clears the radio-item type flag for those items. DeleteMenu
BOOL DeleteMenu(UINT uPosition, UINT uFlags);Deletes an item from the specified menu. EnableMenuItem
UINT EnableMenuItem(UINT uIDEnableItem, UINT uEnable);Enables, disables, or grays the specified menu item. The uEnable parameter must be a combination of either MF_BYCOMMAND or MF_BYPOSITION and MF_ENABLED, MF_DISABLED, or MF_GRAYED. GetDefaultItem
UINT GetDefaultItem(UINT gmdiFlags, BOOL fByPos = FALSE);Determines the default menu item. The gmdiFlags parameter specifies how the function searches for menu items. This parameter can be zero or more of the following values: GMDI_GOINTOPOPUPS; GMDI_USEDISABLED. GetMenuContextHelpId
DWORD GetMenuContextHelpId() const;Retrieves the Help context identifier associated with the menu. GetMenuInfo
BOOL GetMenuInfo(LPMENUINFO lpcmi) const;Retrieves the menu information. GetMenuItemCount
UINT GetMenuItemCount() const;Retrieves the number of menu items. GetMenuItemID
UINT GetMenuItemID(int nPos) const;Retrieves the menu item identifier of a menu item located at the specified position GetMenuItemInfo
BOOL GetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos = FALSE);Retrieves information about the specified menu item. GetMenuState
UINT GetMenuState(UINT uID, UINT uFlags) const;Retrieves the menu flags associated with the specified menu item. Possible values for uFlags are: MF_BYCOMMAND (default) or MF_BYPOSITION. GetMenuString
int GetMenuString(UINT uIDItem, LPTSTR lpString, int nMaxCount, UINT uFlags) const;
int GetMenuString(UINT uIDItem, CString& rString, UINT uFlags) const;Copies the text string of the specified menu item into the specified buffer. GetSubMenu
CMenu* GetSubMenu(int nPos);Retrieves the CMenu object of a pop-up menu. InsertMenu
BOOL InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem = 0, LPCTSTR lpszNewItem = NULL);
BOOL InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp);Inserts a new menu item into a menu, moving other items down the menu. InsertMenuItem
BOOL InsertMenuItem(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos = FALSE);Inserts a new menu item at the specified position in a menu. ModifyMenu
BOOL ModifyMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem = 0, LPCTSTR lpszNewItem = NULL);
BOOL ModifyMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp);Changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item. RemoveMenu
BOOL RemoveMenu(UINT uPosition, UINT uFlags);Deletes a menu item or detaches a submenu from the menu. SetDefaultItem
BOOL SetDefaultItem(UINT uItem, BOOL fByPos = FALSE);Sets the default menu item for the menu. SetMenuContextHelpId
BOOL SetMenuContextHelpId(DWORD dwContextHelpId);Associates a Help context identifier with the menu. SetMenuInfo
BOOL SetMenuInfo(LPCMENUINFO lpcmi);Writes the specified buffer to the file. SetMenuItemBitmaps
BOOL SetMenuItemBitmaps(UINT uPosition, UINT uFlags, const CBitmap* pBmpUnchecked, const CBitmap* pBmpChecked);Associates the specified bitmap with a menu item. SetMenuItemInfo
BOOL SetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos = FALSE);Changes information about a menu item. Operators operator HMENU ()
operator HMENU () const;Retrieves the menu's handle.
Remarks
CMenu objects can be used anywhere a a handle to a menu (HMENU) might be used. They can be substituted for the HMENU in any of the Windows API functions which use a HMENU as a function argument. The benefit of using a CMenu object is that it automatically deletes the menu when it is destroyed.
Summary Information
| Header file | file.h |
| Win32/64 support | Yes |
| WinCE support | Yes |