Simple Splitter | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 7, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

 

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)

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.