Toolbar within splitter windows


How to Help Your Business Become an AI Early Adopter

Environment: -->


Has anyone ever wondered how to dock a toolbar inside a splitter pane? Normally you cannot do that, but you can alter your splitter pane so that it will look just like you placed a toolbar on one of it's sides. The trick is to create a two-pane splitter where your initial pane was; but not just any splitter, we will use our own, which does not allow resizing, and has different border settings. There is one additional view to create, and we will derive a class from CFormView since features provided by this class are closer to our goal.

The code

First goes the custom splitter window:

// class definition
classCSmartSplitterWnd :public CSplitterWnd
	virtual ~CSmartSplitterWnd();
	intHitTest(CPoint pt)const;

// class implementation
	m_cxSplitter=3;      // put your own values here, to make the splitter fit your needs


BEGIN_MESSAGE_MAP(CSmartSplitterWnd, CSplitterWnd)

intCSmartSplitterWnd::HitTest(CPoint pt)const
	// do not allow caller to see mouse hits
	return 0;

Next, we must create a simple CFormView using the resource editor and ClassWizard. You can add any controls to your form view, but you must keep in mind that handling the WM_SIZE message may help you improve the look of your view. There are several ways to update your buttons and other controls inside the view; you may need to implement one of them to update, enable or disable the controls.

The last step is to create the splitter itself and the views. The code below matches a SDI application that accomodates the code above inside a splitter pane, but you can easily adjust it to fit your needs.

First add a member to the CMainFrame class of type CSmartSplitterWnd:

classCMainFrame :public CFrameWnd
	CSmartSplitterWnd m_barSplitter;

In the OnCreateClient member of the CMainFrame class, add code to create the splitter inside the right pane:

// create the splitter window
if (!m_barSplitter.CreateStatic(&m_parentSplitter, 2, 1, WS_CHILD|WS_VISIBLE|WS_BORDER, 
	m_parentSplitter.IdFromRowCol(1, 0))) returnfalse;

// create the views
m_barSplitter.CreateView(0, 0, RUNTIME_CLASS(CBarView), CSize(0, 0), pContext);
m_barSplitter.CreateView(1, 0, RUNTIME_CLASS(CTheView), CSize(0, 0), pContext);
// then set heights

The code is quite easy to follow and change to meet your needs, but if you need assistance, contact me. Also please send me bugs or updates, to keep this solution up-to-date. For more details on the sample application, contact me.

Date Last Updated: February 3, 1999


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date