A pair of splitter classes used in dialogbox | CodeGuru

A pair of splitter classes used in dialogbox

 Download Source Code and Sample Project Many programmers are interesting in splitter that using in dialogbox, so do I. When I read the article General Purpose Splitter Class written by Yurong Lin, I got an idea to make my own classes. Anyway, Lin‘s splitter is very good and easy to use, but it has some […]

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

 Download Source Code and Sample Project

Many programmers are interesting in splitter that using in dialogbox, so do I.

When I read the article General Purpose
Splitter Class
written by Yurong
Lin
, I got an idea to make my own classes.

Anyway, Lin‘s splitter is very good and easy to use, but it has some
limitation, such as: 1) do not support more than one pane on one side of the splitter; 2)
do not support vertical split; 3) no dragging restriction. Fortunately, it is not very
hard to add these features.

Here is the project I’v made, it was built with VC5.0 & MFC version 4.21.

Two classes are provided: CxSplitterWnd & CySplitterWnd, to use them, follow the
steps below:

1. Add the source files to your own project, they are xySplitterWnd.h &
xySplitterWnd.cpp .

2. Create an picture control in the dialog resource, this control will act as a
splitter afterward.

Set the type as Frame, move it to the appropriate position, then give
it an ID, such as IDC_XBAR1. One picture control for one splitter, you can make any number
of splitters as you like.

3. Declare the objects of CxSplitterWnd/CySplitterWnd in your dialog class.

Of course, you should include xySplitterWnd.h first.

    CxSplitterWnd m_xSplitter1, m_xSplitter2;
    CySplitterWnd m_ySplitter;

4. Initiate the splitter objects in the InitDialog function.

    m_xSplitter1.BindWithControl(this, IDC_XBAR1);  // bind the splitter object to the puppet control
    m_xSplitter1.SetMinWidth(10, 50);  // set the minimum width of the left/right pane 

    m_xSplitter1.AttachAsRightPane(IDC_LEFTPANE1);  // attach a control within the same dialogbox as a pane of the splitter
    m_xSplitter1.AttachAsRightPane(IDC_YBAR);       // you can even attach another splitter as a pane
    m_xSplitter1.AttachAsRightPane(IDC_LEFTPANE2);

    m_xSplitter1.RecalcLayout();
Advertisement

5. Un-bind the splitter object with the puppet control when dialogbox is going to
close.

This step can be omitted when you do not want to re-use the splitter object.

    m_xSplitter1.Unbind();

 

Just as Lin‘s work, there is a message "WM_SPLITTER_MOVED"
that generated by the splitter bar whenever the splitter is dragged then dropped. If you
want to do something special when the splitter is repositioned, then provide a message
handler for this message.

 

Last updated: 13. July 1998

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.