Simple Splitter

 

I have seen many programmers asking how to create a splitter window in a dialog box.
Unfortunately MFC does not provide a splitter control that can be directly embedded into a
dialog box. CSplitterWnd is somehow designed to be used only inside a frame window. I have
also seen a few attempts, but none is generic and easy to use.

The class I am presenting is designed for general purpose. The name is CSplitterBar,
the function is to provide a splitter bar that can be embedded into any kind of windows,
such as a frame, a view or a dialog box.

The example I am giving here is to create a CSplitterbar control in a dialog box. If
you would like to use CSplitterBar in other kinds of windows, the procedure described here
can be easily adapted.

  1. Firstly, declare an object of CSplitterBar in your dialog class:

CSplitterBar m_wndSplitterBar;

2. Secondly, create the m_wndSplitterBar object in the InitDialog function:

 

//Create a splitter bar

CRect rect(0,0,0,0);

m_wndSplitterBar.Create(WS_CHILD|WS_BORDER|WS_DLGFRAME|WS_VISIBLE, rect,this,999);

 

3. Finally, setup the windows on the left pane and right pane of the splitter bar:

//Insert the splitter bar
between a tree and a list control

m_wndSplitterBar.SetPanes(&m_wndTree,&m_wndList);

 

That is all your need to do, and let the CSplitterBar handle all of the rest. The full
source code can be downloaded from here:

To use CSplitterBar in your own project, you only need to include two files:
SplitterBar.h and SplitterBar.cpp.

Note:

There is also a message "WM_SPLITTER_MOVED" is generated by the splitter bar
whenever the control is dragged then dropped. If you want to do something special when the
splitter is repositioned, then provide a message handler for this message.

Download Documentation and Source simple_splitter.zip
(48.5k)

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read