SplitterBar control

This article was submitted .

The SplitterBar control is a subclassed STATIC Windows control, which has the functionality of a splitter. The WTL library already comes with a splitter control packed with neat features, but it's designed as a container window so initializing and handling it in the application sometimes become tedious. For instance, adding a splitter in a dialog is not always straightforward.

In many cases we just need to allow the user to adjust the layout between two controls. The perfect example is the TreeView and ListView in any Explorer-type application. The SplitterBar control creates a drag-bar between the two controls and allows their middle to be dragged from one side to another - adjusting the size of both controls. The control itself is a child control, and does not hook itself up as parent to the participating windows.

Unlike the real WTL Splitter, this control doesn't include any of the additional functionality - such as proportional split, splitter with one pane only, etc etc. It's just for use in the special case - where only two controls are involved.

The control supports the SS_OWNERDRAW style, making it owner-drawn and sending out WM_DRAWITEM messages to allow you to style its appearance.

To use it, place a STATIC control (label) on your dialog. Place it between the two controls you wish to make adjustable.
Add a member variable to your dialog implementation file...

CVertSplitterCtrl m_ctrlSplit
In the OnInitDialog() event handler, add the following lines:
LRESULT OnInitDialog(UINT /*uMsg*/, 
                     WPARAM /*wParam*/, 
                     LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)
  m_ctrlSplit.SetSplitterPanes(m_ctrlLeft, m_ctrlRight);

There's both a CVertSplitterCtrl and a CHorSplitterCtrl included for respectively a vertical and horizontal splitter.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.0 Library

Download Files

DownloadSource Code (4 Kb)

To the top