Udostępnij za pośrednictwem


CMFCToolBarButton Class

Provides button functionality to toolbars.

class CMFCToolBarButton : public CObject

Members

Public Constructors

Name

Description

CMFCToolBarButton::CMFCToolBarButton

Constructs and initializes a CMFCToolBarButton object.

CMFCToolBarButton::~CMFCToolBarButton

Destructor.

Public Methods

Name

Description

CMFCToolBarButton::CanBeDropped

Specifies whether a user can position a button on a toolbar or menu during customization.

CMFCToolBarButton::CanBeStored

Specifies whether the button can be stored.

CMFCToolBarButton::CanBeStretched

Specifies whether a user can stretch the button during customization.

CMFCToolBarButton::CompareWith

Compares this instance with the provided CMFCToolBarButton object.

CMFCToolBarButton::CopyFrom

Copies the properties of another toolbar button to the current button.

CMFCToolBarButton::CreateFromOleData

Creates a CMFCToolBarButton object from the provided COleDataObject object.

CMFCToolBarButton::CreateObject

Used by the framework to create a dynamic instance of this class type.

CMFCToolBarButton::EnableWindow

Enables or disables mouse and keyboard input.

CMFCToolBarButton::ExportToMenuButton

Copies text from the toolbar button to a menu.

CMFCToolBarButton::GetClipboardFormat

Retrieves the global clipboard format for the application.

CMFCToolBarButton::GetHwnd

Retrieves the window handle that is associated with the toolbar button.

CMFCToolBarButton::GetImage

Retrieves the image index of the button.

CMFCToolBarButton::GetInvalidateRect

Retrieves the region of the client area of the button that must be redrawn.

CMFCToolBarButton::GetParentWnd

Retrieves the parent window of the button.

CMFCToolBarButton::GetProtectedCommands

Retrieves the list of commands that the user cannot customize.

CMFCToolBarButton::GetTextSize

Retrieves the size of the button text.

CMFCToolBarButton::HasFocus

Determines whether the button has the current input focus.

CMFCToolBarButton::HaveHotBorder

Determines whether a border of the button is displayed when a user selects the button.

CMFCToolBarButton::IsDrawImage

Determines whether an image is displayed on the button.

CMFCToolBarButton::IsDrawText

Determines whether a text label is displayed on the button.

CMFCToolBarButton::IsDroppedDown

Determines whether the button displays a submenu.

CMFCToolBarButton::IsEditable

Determines whether the button can be customized.

CMFCToolBarButton::IsExtraSize

Determines whether the button can be displayed with an extended border.

CMFCToolBarButton::IsFirstInGroup

Determines whether the button is in the first position in its button group.

CMFCToolBarButton::IsHidden

Determines whether the button is hidden.

CMFCToolBarButton::IsHorizontal

Determines whether the button is located on a horizontal toolbar.

CMFCToolBarButton::IsLastInGroup

Specifies whether the button is in the last position in its button group.

CMFCToolBarButton::IsLocked

Determines whether the button is on a locked (non-customizable) toolbar.

CMFCToolBarButton::IsOwnerOf

Determines whether the button is the owner of the provided window handle.

CMFCToolBarButton::IsVisible

Determines whether the toolbar button is visible.

CMFCToolBarButton::IsWindowVisible

Determines whether the underlying window handle of the button is visible.

CMFCToolBarButton::NotifyCommand

Specifies whether the button processes the WM_COMMAND message.

CMFCToolBarButton::OnAddToCustomizePage

Called by the framework when the button is added to a Customize dialog box.

CMFCToolBarButton::OnBeforeDrag

Specifies whether the button can be dragged.

CMFCToolBarButton::OnBeforeDrop

Specifies whether a user can drop the button onto the target toolbar.

CMFCToolBarButton::OnCalculateSize

Called by the framework to calculate the size of the button for the specified device context and docking state.

CMFCToolBarButton::OnCancelMode

Called by the framework to handle the WM_CANCELMODE message.

CMFCToolBarButton::OnChangeParentWnd

Called by the framework when the button is inserted into a new toolbar.

CMFCToolBarButton::OnClick

Called by the framework when the user clicks the mouse button.

CMFCToolBarButton::OnClickUp

Called by the framework when the user releases the mouse button.

CMFCToolBarButton::OnContextHelp

Called by the framework when the parent toolbar handles a WM_HELPHITTEST message.

CMFCToolBarButton::OnCtlColor

Called by the framework when the parent toolbar handles a WM_CTLCOLOR message.

CMFCToolBarButton::OnCustomizeMenu

Allows the button to modify the provided menu when the application displays a shortcut menu on the parent toolbar.

CMFCToolBarButton::OnDblClk

Called by the framework when the parent toolbar handles a WM_LBUTTONDBLCLK message.

CMFCToolBarButton::OnDraw

Called by the framework to draw the button by using the specified styles and options.

CMFCToolBarButton::OnDrawOnCustomizeList

Called by the framework to draw the button in the Commands pane of the Customize dialog box.

CMFCToolBarButton::OnGetCustomToolTipText

Called by the framework to retrieve the custom tooltip text for the button.

CMFCToolBarButton::OnGlobalFontsChanged

Called by the framework when the global font has changed.

CMFCToolBarButton::OnMove

Called by the framework when the parent toolbar moves.

CMFCToolBarButton::OnShow

Called by the framework when the button becomes visible or invisible.

CMFCToolBarButton::OnSize

Called by the framework when the parent toolbar changes its size or position and this change requires the button to change size.

CMFCToolBarButton::OnToolHitTest

Called by the framework when the parent toolbar must determine whether a point is in the bounding rectangle of the button.

CMFCToolBarButton::OnUpdateToolTip

Called by the framework when the parent toolbar updates its tooltip text.

CMFCToolBarButton::PrepareDrag

Called by the framework when the button is about to perform a drag-and-drop operation.

CMFCToolBarButton::Rect

Retrieves the bounding rectangle of the button.

CMFCToolBarButton::ResetImageToDefault

Sets to the default value the image that is associated with the button.

CMFCToolBarButton::SaveBarState

Saves the state of the toolbar button.

CMFCToolBarButton::Serialize

Reads this object from an archive or writes it to an archive. (Overrides CObject::Serialize.)

CMFCToolBarButton::SetACCData

Populates the provided CAccessibilityData object with accessibility data from the toolbar button.

CMFCToolBarButton::SetClipboardFormatName

Renames the global clipboard format.

CMFCToolBarButton::SetImage

Sets the image index of the button.

CMFCToolBarButton::SetProtectedCommands

Sets the list of commands that the user cannot customize.

CMFCToolBarButton::SetRadio

Called by the framework when a button changes its checked state.

CMFCToolBarButton::SetRect

Sets the bounding rectangle of the button.

CMFCToolBarButton::SetStyle

Sets the style of the button.

CMFCToolBarButton::SetVisible

Specifies whether the button is visible.

CMFCToolBarButton::Show

Shows or hides the button.

Data Members

Name

Description

CMFCToolBarButton::m_bImage

Specifies whether an image is displayed on the button.

CMFCToolBarButton::m_bText

Specifies whether a text label is displayed on the button.

CMFCToolBarButton::m_bTextBelow

Specifies whether the text label is displayed underneath the image on the button.

CMFCToolBarButton::m_bUserButton

Specifies whether the button has a user-defined image.

CMFCToolBarButton::m_bWholeText

Specifies whether the button displays its full text label even if it does not fit in the bounding rectangle.

CMFCToolBarButton::m_bWrap

Specifies whether the button next to a separator will be put on the next row.

CMFCToolBarButton::m_bWrapText

Specifies whether multi-line text labels are enabled.

CMFCToolBarButton::m_nID

The command ID of the button.

CMFCToolBarButton::m_nStyle

The style of the button.

CMFCToolBarButton::m_strText

The text label of the button.

Remarks

A CMFCToolbarButton object is a control that resides on a toolbar. Its behavior resembles that of an ordinary button. You can assign an image and a text label to this object. A toolbar button can also have a command ID. When the user clicks the toolbar button, the framework executes the command that this ID specifies.

Typically, toolbar buttons can be customized: the user can drag buttons from one toolbar to another, and copy, paste, delete, and edit text labels and images. To prevent the user from customizing the toolbar, you can lock the toolbar in one of two ways. Either set the bLocked flag to TRUE when you call CMFCToolBar::LoadToolBar, or add the command ID of an individual button to the global list of protected commands by using the CMFCToolBarButton::SetProtectedCommands method.

CMFCToolBarButton objects display images from the global collections of toolbar images in the application. These collections are maintained by the parent toolbar, CMFCToolBar Class. For more information, see CMFCToolBarImages Class.

When the user clicks a toolbar button, its parent toolbar processes the mouse message and communicates the appropriate actions to the button. If the button has a valid command ID, the parent toolbar sends the WM_COMMAND message to the parent frame.

The CMFCToolBarButton class is the base class for other toolbar button classes, such as CMFCToolBarMenuButton Class, CMFCToolBarEditBoxButton Class, and CMFCToolBarComboBoxButton Class.

Example

The following example demonstrates how to configure a CMFCToolBarButton object by using various methods in the CMFCToolBarButton class. The example illustrates how to enable the mouse and keyboard input, set the image index of the button, set the bounding rectangle of the button, and make the button visible. This code snippet is part of the TabControl Sample: MFC Tab Control Application.

  CMFCToolBarButton* pOffice2007 = NULL;
    int nIndex = -1;
    
    for (UINT uiCmd = ID_VIEW_APPLOOK_2007_1; uiCmd <= ID_VIEW_APPLOOK_2007_4; uiCmd+)
    {
        // CMFCToolBar  m_wndToolBarTheme
        nIndex = m_wndToolBarTheme.CommandToIndex (uiCmd);

        CMFCToolBarButton* pButton = m_wndToolBarTheme.GetButton (nIndex);
    
        if (pButton != NULL)
        {
            pOffice2007 = pButton;
            break;
        }
    }


...


    pOffice2007->EnableWindow();
    pOffice2007->SetImage(1);
    pOffice2007->SetRect( CRect(1,1,1,1));
    pOffice2007->SetVisible();
    pOffice2007->Show(true);

Inheritance Hierarchy

CObject

   CMFCToolBarButton

Requirements

Header: afxtoolbarbutton.h

See Also

Concepts

MFC Hierarchy Chart

Reference

CMFCToolBar Class

CMFCToolBarImages Class

CMFCToolBarButton::OnClick

CMFCToolBarButton::NotifyCommand

Other Resources

Classes (MFC Feature Pack)