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

CMFCMenuButton::CMFCMenuButton

Constructs a CMFCMenuButton object.

Public Methods

Name

Description

CMFCMenuButton::PreTranslateMessage

Called by the framework to translate window messages before they are dispatched. (Overrides CMFCButton::PreTranslateMessage.)

CMFCMenuButton::SizeToContent

Changes the size of the button according to its text and image size.

Data Members

Name

Description

CMFCMenuButton::m_bOSMenu

Specifies whether to display the default system pop-up menu or to use CContextMenuManager::TrackPopupMenu.

CMFCMenuButton::m_bRightArrow

Specifies whether the pop-up menu will appear underneath or to the right of the button.

CMFCMenuButton::m_bStayPressed

Specifies whether the menu button changes its state after the user releases the button.

CMFCMenuButton::m_hMenu

A handle to the attached Windows menu.

CMFCMenuButton::m_nMenuResult

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

CObject

   CCmdTarget

      CWnd

         CButton

            CMFCButton

               CMFCMenuButton

Requirements

Header: afxmenubutton.h

See Also

Reference

Hierarchy Chart

CMFCButton Class

Other Resources

MFC Classes