CMFCMenuButton Class
A button that displays a pop-up menu and reports on the user's menu selections.
class CMFCMenuButton : public CMFCButton
Members
Public Constructors
Name |
Description |
---|---|
Constructs a CMFCMenuButton object. |
Public Methods
Name |
Description |
---|---|
(Overrides CMFCButton::PreTranslateMessage.) |
|
Changes the size of the button according to its text and image size. |
Data Members
Name |
Description |
---|---|
Specifies whether to display the default system pop-up menu or to use CContextMenuManager::TrackPopupMenu. |
|
Specifies whether the pop-up menu will appear underneath or to the right of the button. |
|
Specifies whether the menu button changes its state after the user releases the button. |
|
A handle to the attached Windows menu. |
|
An identifier that indicates which item the user selected from the pop-up menu. |
Remarks
The CMFCMenuButton class is derived from the CMFCButton Class which is, in turn, derived from the CButton Class. Therefore, you can use CMFCMenuButton in your code the same way you would use CButton.
When you create a CMFCMenuButton, you must pass in a handle to the associated pop-up menu. Next, call the function CMFCMenuButton::SizeToContent. CMFCMenuButton::SizeToContent checks that the button size is sufficient to include an arrow that points to the location where the pop-up window will appear - namely, underneath or to the right of the button.
Example
The following example demonstrates how to set the handle of the menu attached to the button, resize the button according to its text and image size, and set the pop-up menu that is displayed by the framework. This code snippet is part of the New Controls sample.
CMFCMenuButton m_btnMenu;
...
// CMenu m_menu
m_btnMenu.m_hMenu = m_menu.GetSubMenu(0)->GetSafeHmenu();
m_btnMenu.SizeToContent();
// set to FALSE so that the framework calls CContextMenuManager::TrackPopupMenu
// to display its menu
m_btnMenu.m_bOSMenu = FALSE;
Inheritance Hierarchy
Requirements
Header: afxmenubutton.h