Partager via


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

CMFCRibbonButton::CMFCRibbonButton

Constructs a ribbon button object.

Public Methods

Name

Description

CMFCRibbonButton::AddSubItem

Adds a menu item to the pop-up menu that is associated with the button.

CMFCRibbonButton::CanBeStretched

  (Overrides CMFCRibbonBaseElement::CanBeStretched.)

CMFCRibbonButton::CleanUpSizes

  (Overrides CMFCRibbonBaseElement::CleanUpSizes.)

CMFCRibbonButton::ClosePopupMenu

  (Overrides CMFCRibbonBaseElement::ClosePopupMenu.)

CMFCRibbonButton::DrawBottomText

 

CMFCRibbonButton::DrawImage

  (Overrides CMFCRibbonBaseElement::DrawImage.)

CMFCRibbonButton::DrawRibbonText

 

CMFCRibbonButton::FindSubItemIndexByID

Returns the index of a pop-up menu item that is associated with the specified command ID.

CMFCRibbonButton::GetCommandRect

 

CMFCRibbonButton::GetCompactSize

Returns the compact size of the ribbon element. (Overrides CMFCRibbonBaseElement::GetCompactSize.)

CMFCRibbonButton::GetIcon

 

CMFCRibbonButton::GetImageIndex

Returns the index of the image that is associated with the button.

CMFCRibbonButton::GetImageSize

Returns the image size of the ribbon element. (Overrides CMFCRibbonBaseElement::GetImageSize.)

CMFCRibbonButton::GetIntermediateSize

Returns the size of the ribbon element in its intermediate state. (Overrides CMFCRibbonBaseElement::GetIntermediateSize.)

CMFCRibbonButton::GetMenu

Returns a handle to a Windows menu that is assigned to the ribbon button.

CMFCRibbonButton::GetMenuRect

 

CMFCRibbonButton::GetRegularSize

Returns the regular size of the ribbon element. (Overrides CMFCRibbonBaseElement::GetRegularSize.)

CMFCRibbonButton::GetSubItems

 

CMFCRibbonButton::GetTextRowHeight

 

CMFCRibbonButton::GetToolTipText

Returns tooltip text of the ribbon element. (Overrides CMFCRibbonBaseElement::GetToolTipText.)

CMFCRibbonButton::HasCompactMode

Specifies whether the ribbon element has a compact mode. (Overrides CMFCRibbonBaseElement::HasCompactMode.)

CMFCRibbonButton::HasIntermediateMode

Specifies whether the ribbon element has an intermediate mode. (Overrides CMFCRibbonBaseElement::HasIntermediateMode.)

CMFCRibbonButton::HasLargeMode

Determines whether the ribbon element has a large mode. (Overrides CMFCRibbonBaseElement::HasLargeMode.)

CMFCRibbonButton::HasMenu

  (Overrides CMFCRibbonBaseElement::HasMenu.)

CMFCRibbonButton::IsAlwaysDrawBorder

 

CMFCRibbonButton::IsAlwaysLargeImage

  (Overrides CMFCRibbonBaseElement::IsAlwaysLargeImage.)

CMFCRibbonButton::IsApplicationButton

 

CMFCRibbonButton::IsCommandAreaHighlighted

 

CMFCRibbonButton::IsDefaultCommand

Determines whether you have enabled the default command for a ribbon button.

CMFCRibbonButton::IsDefaultPanelButton

 

CMFCRibbonButton::IsDrawTooltipImage

 

CMFCRibbonButton::IsLargeImage

 

CMFCRibbonButton::IsMenuAreaHighlighted

 

CMFCRibbonButton::IsMenuOnBottom

 

CMFCRibbonButton::IsPopupDefaultMenuLook

 

CMFCRibbonButton::IsRightAlignMenu

Determines whether the menu is right-aligned.

CMFCRibbonButton::IsSingleLineText

 

CMFCRibbonButton::OnCalcTextSize

  (Overrides CMFCRibbonBaseElement::OnCalcTextSize.)

CMFCRibbonButton::OnDrawBorder

 

CMFCRibbonButton::OnDraw

Called by the framework to draw the ribbon element. (Overrides CMFCRibbonBaseElement::OnDraw.)

CMFCRibbonButton::OnFillBackground

 

CMFCRibbonButton::RemoveAllSubItems

Removes all menu items from the pop-up menu.

CMFCRibbonButton::RemoveSubItem

Removes a menu item from the pop-up menu.

CMFCRibbonButton::SetACCData

  (Overrides CMFCRibbonBaseElement::SetACCData.)

CMFCRibbonButton::SetAlwaysLargeImage

Specifies whether the button displays a large or a small image when the user collapses the button.

CMFCRibbonButton::SetDefaultCommand

Enables the default command for the ribbon button.

CMFCRibbonButton::SetDescription

Sets the description for the ribbon element. (Overrides CMFCRibbonBaseElement::SetDescription.)

CMFCRibbonButton::SetImageIndex

Assigns an index to the image of the button.

CMFCRibbonButton::SetMenu

Assigns a pop-up menu to the ribbon button.

CMFCRibbonButton::SetParentCategory

  (Overrides CMFCRibbonBaseElement::SetParentCategory.)

CMFCRibbonButton::SetRightAlignMenu

Aligns the pop-up menu to the right of the button.

CMFCRibbonButton::SetText

Sets the text for the ribbon element. (Overrides CMFCRibbonBaseElement::SetText.)

Protected Methods

Name

Description

CMFCRibbonButton::OnClick

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

CObject

   CMFCRibbonBaseElement

      CMFCRibbonButton

Requirements

Header: afxribbonbutton.h

See Also

Reference

Hierarchy Chart

Other Resources

MFC Classes