CMFCRibbonButton Class
The CMFCRibbonButton class implements buttons that you can position on ribbon bar elements such as panels, Quick Access Toolbars, and pop-up menus.
class CMFCRibbonButton : public CMFCRibbonBaseElement
Members
Public Constructors
Name |
Description |
---|---|
Constructs a ribbon button object. |
Public Methods
Name |
Description |
---|---|
Adds a menu item to the pop-up menu that is associated with the button. |
|
(Overrides CMFCRibbonBaseElement::CanBeStretched.) |
|
(Overrides CMFCRibbonBaseElement::CleanUpSizes.) |
|
(Overrides CMFCRibbonBaseElement::ClosePopupMenu.) |
|
|
|
(Overrides CMFCRibbonBaseElement::DrawImage.) |
|
|
|
Returns the index of a pop-up menu item that is associated with the specified command ID. |
|
|
|
Returns the compact size of the ribbon element. (Overrides CMFCRibbonBaseElement::GetCompactSize.) |
|
|
|
Returns the index of the image that is associated with the button. |
|
Returns the image size of the ribbon element. (Overrides CMFCRibbonBaseElement::GetImageSize.) |
|
Returns the size of the ribbon element in its intermediate state. (Overrides CMFCRibbonBaseElement::GetIntermediateSize.) |
|
Returns a handle to a Windows menu that is assigned to the ribbon button. |
|
|
|
Returns the regular size of the ribbon element. (Overrides CMFCRibbonBaseElement::GetRegularSize.) |
|
|
|
|
|
Returns tooltip text of the ribbon element. (Overrides CMFCRibbonBaseElement::GetToolTipText.) |
|
Specifies whether the ribbon element has a compact mode. (Overrides CMFCRibbonBaseElement::HasCompactMode.) |
|
Specifies whether the ribbon element has an intermediate mode. (Overrides CMFCRibbonBaseElement::HasIntermediateMode.) |
|
Determines whether the ribbon element has a large mode. (Overrides CMFCRibbonBaseElement::HasLargeMode.) |
|
(Overrides CMFCRibbonBaseElement::HasMenu.) |
|
|
|
(Overrides CMFCRibbonBaseElement::IsAlwaysLargeImage.) |
|
|
|
|
|
Determines whether you have enabled the default command for a ribbon button. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Determines whether the menu is right-aligned. |
|
|
|
(Overrides CMFCRibbonBaseElement::OnCalcTextSize.) |
|
|
|
Called by the framework to draw the ribbon element. (Overrides CMFCRibbonBaseElement::OnDraw.) |
|
|
|
Removes all menu items from the pop-up menu. |
|
Removes a menu item from the pop-up menu. |
|
(Overrides CMFCRibbonBaseElement::SetACCData.) |
|
Specifies whether the button displays a large or a small image when the user collapses the button. |
|
Enables the default command for the ribbon button. |
|
Sets the description for the ribbon element. (Overrides CMFCRibbonBaseElement::SetDescription.) |
|
Assigns an index to the image of the button. |
|
Assigns a pop-up menu to the ribbon button. |
|
(Overrides CMFCRibbonBaseElement::SetParentCategory.) |
|
Aligns the pop-up menu to the right of the button. |
|
Sets the text for the ribbon element. (Overrides CMFCRibbonBaseElement::SetText.) |
Protected Methods
Name |
Description |
---|---|
Called by the framework when the user clicks the button. |
Example
The following example demonstrates how to use the various methods in the CMFCRibbonButton class. The example shows how to construct an object of the CMFCRibbonButton class, assign a pop-up menu to the ribbon button, set the description of the button, remove a menu item from the pop-up menu, and right align the pop-up menu to the edge of the button.
strTemp.LoadString(IDS_RIBBON_STYLE);
// The first parameter is the command ID of the button.
// The third parameter is a zero-based index of the button's small image in the
// image list of the parent category.
// The fourth parameter is a zero-based index of the button's large image in the
// image list of the parent category.
CMFCRibbonButton* pVisualStyleButton = new CMFCRibbonButton(1, strTemp, -1, -1);
pVisualStyleButton->SetMenu(IDR_THEME_MENU, TRUE, TRUE);
strTemp.LoadString(IDS_RIBBON_STYLE_TIP);
pVisualStyleButton->SetToolTipText(strTemp);
strTemp.LoadString(IDS_RIBBON_STYLE_DESC);
pVisualStyleButton->SetDescription(strTemp);
pVisualStyleButton->RemoveSubItem(0);
pVisualStyleButton->SetRightAlignMenu(TRUE);
Remarks
To use a ribbon button in an application, construct the button object and add it to the appropriate ribbon panel.
CMFCRibbonPanel* pPanel = pCategory->AddPanel (
_T("Clipboard"), // Panel name
m_PanelIcons.ExtractIcon (0)); // Panel icon
// Create the first button ("Paste"):
CMFCRibbonButton* pPasteButton =
new CMFCRibbonButton (ID_EDIT_PASTE, _T("Paste"), -1, 0);
// The third parameter (-1) disables small images for button.
// This button is always displayed with a large image
// Associate a pop-up menu with the "Paste" button:
pPasteButton->SetMenu (IDR_CONTEXT_MENU);
// Add buttons to the panel. These buttons have only small images.
pPanel->Add (new CMFCRibbonButton (ID_EDIT_CUT, _T("Cut"), 1));
pPanel->Add (new CMFCRibbonButton (ID_EDIT_COPY, _T("Copy"), 2));
pPanel->Add (new CMFCRibbonButton (ID_EDIT_PAINT, _T("Paint"), 9));
Inheritance Hierarchy
Requirements
Header: afxribbonbutton.h