Articles and Tutorials

Add a splitter popup button that doesn't disappear

Author: Kirk Stowell
Platform: Visual C++ MFC

If you have created a splitter popup button as shown below, it will disappear when the ‘Reset Toolbar’ button is clicked.

pStandardBar->GetControls()->Add(xtpControlSplitButtonPopup, ID_BUTTON_POPUP);

If you use Customizable toolbars you must avoid dynamic creation of controls. You must use the ‘Control Sub classing’ technique. To add a splitter button do the following:

1. Add the button to your toolbar resource using the Visual Studio resource editor like so:

Splitter Button

2. Using the resource editor, create a Popup menu with same command id as the toolbar button you just added.

3. Add the command handler ON_XTP_CREATECONTROL() to your CMainFrame message map.


int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
    if (lpCreateControl->bToolBar)
        if (lpCreateControl->nID == ID_BUTTON_POPUP)
            lpCreateControl->controlType = xtpControlSplitButtonPopup;
            return TRUE;
    return FALSE;

4. Add the following line to your header file for CMainFrame:

afx_msg int OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl);

Application screen shot showing splitter popup button:

Splitter Button

Articles and Tutorials