CMFCToolBar::ReplaceButton

Replaces a toolbar button with another toolbar button.

int ReplaceButton(
   UINT uiCmd,
   const CMFCToolBarButton& button,
   BOOL bAll=FALSE 
);

Parameters

  • [in] uiCmd
    The command ID of the button to replace.

  • [in] button
    A reference to the CMFCToolBarButton to insert.

  • [in] bAll
    A Boolean value that specifies whether to replace all buttons that have the command ID specified by uiCmd. If this parameter is TRUE, all buttons that have the specified command ID are replaced. Otherwise, the first button is replaced.

Return Value

The number of buttons that are replaced. This method returns 0 if a button with the specified command ID does not exist on the toolbar.

Remarks

Call this method when you want to add toolbar buttons that cannot be loaded from resources. You can create a placeholder button at design-time and replace that button with a custom button when you initialize the toolbar. See the VisualStudioDemo sample for an example that uses this method.

Example

The following example demonstrates how to use the ReplaceButton method in the CMFCToolBar class. This code snippet is part of the IE Demo sample.

   CMFCToolBar     m_wndToolBar;


...


        // CMenu menuHistory 
        // CString str
        m_wndToolBar.ReplaceButton (ID_GO_BACK, 
            CMFCToolBarMenuButton (ID_GO_BACK, menuHistory, 
                        GetCmdMgr ()->GetCmdImage (ID_GO_BACK), str));

Requirements

Header: afxtoolbar.h

See Also

Reference

CMFCToolBar Class

Hierarchy Chart

CMFCToolBarButton Class