Share via


CMenu Class

An encapsulation of the Windows HMENU.

class CMenu : public CObject

Members

Public Constructors

Name

Description

CMenu::CMenu

Constructs a CMenu object.

Public Methods

Name

Description

CMenu::AppendMenu

Appends a new item to the end of this menu.

CMenu::Attach

Attaches a Windows menu handle to a CMenu object.

CMenu::CheckMenuItem

Places a check mark next to or removes a check mark from a menu item in the pop-up menu.

CMenu::CheckMenuRadioItem

Places a radio button next to a menu item and removes the radio button from all of the other menu items in the group.

CMenu::CreateMenu

Creates an empty menu and attaches it to a CMenu object.

CMenu::CreatePopupMenu

Creates an empty pop-up menu and attaches it to a CMenu object.

CMenu::DeleteMenu

Deletes a specified item from the menu. If the menu item has an associated pop-up menu, destroys the handle to the pop-up menu and frees the memory used by it.

CMenu::DeleteTempMap

Deletes any temporary CMenu objects created by the FromHandle member function.

CMenu::DestroyMenu

Destroys the menu attached to a CMenu object and frees any memory that the menu occupied.

CMenu::Detach

Detaches a Windows menu handle from a CMenu object and returns the handle.

CMenu::DrawItem

Called by the framework when a visual aspect of an owner-drawn menu changes.

CMenu::EnableMenuItem

Enables, disables, or dims (grays) a menu item.

CMenu::FromHandle

Returns a pointer to a CMenu object given a Windows menu handle.

CMenu::GetDefaultItem

Determines the default menu item on the specified menu.

CMenu::GetMenuContextHelpId

Retrieves the help context ID associated with the menu.

CMenu::GetMenuInfo

Retrieves information on a specific menu.

CMenu::GetMenuItemCount

Determines the number of items in a pop-up or top-level menu.

CMenu::GetMenuItemID

Obtains the menu-item identifier for a menu item located at the specified position.

CMenu::GetMenuItemInfo

Retrieves information about a menu item.

CMenu::GetMenuState

Returns the status of the specified menu item or the number of items in a pop-up menu.

CMenu::GetMenuString

Retrieves the label of the specified menu item.

CMenu::GetSafeHmenu

Returns the m_hMenu wrapped by this CMenu object.

CMenu::GetSubMenu

Retrieves a pointer to a pop-up menu.

CMenu::InsertMenu

Inserts a new menu item at the specified position, moving other items down the menu.

CMenu::InsertMenuItem

Inserts a new menu item at the specified position in a menu.

CMenu::LoadMenu

Loads a menu resource from the executable file and attaches it to a CMenu object.

CMenu::LoadMenuIndirect

Loads a menu from a menu template in memory and attaches it to a CMenu object.

CMenu::MeasureItem

Called by the framework to determine menu dimensions when an owner-drawn menu is created.

CMenu::ModifyMenu

Changes an existing menu item at the specified position.

CMenu::RemoveMenu

Deletes a menu item with an associated pop-up menu from the specified menu.

CMenu::SetDefaultItem

Sets the default menu item for the specified menu.

CMenu::SetMenuContextHelpId

Sets the help context ID to be associated with the menu.

CMenu::SetMenuInfo

Sets information on a specific menu.

CMenu::SetMenuItemBitmaps

Associates the specified check-mark bitmaps with a menu item.

CMenu::SetMenuItemInfo

Changes information about a menu item.

CMenu::TrackPopupMenu

Displays a floating pop-up menu at the specified location and tracks the selection of items on the pop-up menu.

CMenu::TrackPopupMenuEx

Displays a floating pop-up menu at the specified location and tracks the selection of items on the pop-up menu.

Public Operators

Name

Description

CMenu::operator HMENU

Retrieves the handle of the menu object.

CMenu::operator !=

Determines if two menu objects are not equal.

CMenu::operator ==

Determines if two menu objects are equal.

Public Data Members

Name

Description

CMenu::m_hMenu

Specifies the handle to the Windows menu attached to the CMenu object.

Remarks

It provides member functions for creating, tracking, updating, and destroying a menu.

Create a CMenu object on the stack frame as a local, then call CMenu's member functions to manipulate the new menu as needed. Next, call CWnd::SetMenu to set the menu to a window, followed immediately by a call to the CMenu object's Detach member function. The CWnd::SetMenu member function sets the window's menu to the new menu, causes the window to be redrawn to reflect the menu change, and also passes ownership of the menu to the window. The call to Detach detaches the HMENU from the CMenu object, so that when the local CMenu variable passes out of scope, the CMenu object destructor does not attempt to destroy a menu it no longer owns. The menu itself is automatically destroyed when the window is destroyed.

You can use the LoadMenuIndirect member function to create a menu from a template in memory, but a menu created from a resource by a call to LoadMenu is more easily maintained, and the menu resource itself can be created and modified by the menu editor.

Inheritance Hierarchy

CObject

CMenu

Requirements

Header: afxwin.h

See Also

Reference

CObject Class

Hierarchy Chart

CObject Class

Concepts

MFC Sample CTRLTEST

MFC Sample DYNAMENU