Virtual Developer Workshop: Containerized Development with Docker

Environment: VC6 SP3, NT4 SP5

The CSplitterDialog class adds splitter capabilities to a dialog, much like the MFC CSplitterWnd class does to a child frame. Derive your CDialog-derived class from CSplitterDialog and call InitDialog() from your OnInitDialog() override.
Here's the prototype:

void CSplitterDialog::InitDialog( LPCTRLINFO pLeftCtrl, LPCTRLINFO pRightCtrl, UINT nPerc );

The first two parameters are pointers to CTRLINFO structure which describes the controls (targets) managed by the splitter, the third is the initial horizontal dimension of the left control (expressed in percentage of dialog's total dimension).

If the dialog is resizable, the controls are automatically resized to keep the settings of the dialog. It is also possible to define an area on the dialog surface not used by the target controls: at the left of left control, at the right of right control and above or below each control (e.g. to add buttons or bitmaps on the dialog in addition to target controls).
Target controls must belong to a CWnd-derived class (CListCtrl, CTreeCtrl, CButton, CEdit, CStatic, ...)

Below are listed CTRLINFO structure members:

  • CWnd* m_pWnd: pointer to the control;
  • CSize m_sizeMin: specifies minimum allowable size of the control (pixels);
  • UINT m_nOffX: specifies offset (pixels) at the left of the control, for left control, or at the right of the control, for right control;
  • UINT m_nOffY: specifies offset (pixels) above or below the control;
  • UINT m_nHowY: specifies if m_nOffY is an offset above (CSplitterDialog::TOP) or below (CSplitterDialog::BOTTOM) the control.

How to use this class:

  • use resource editor to create a dialog with two target controls and additional controls if you need them. The target controls are resized and repositioned by CSplitterDialog::InitDialog(); the other controls must be managed by the developer (place them in the free area - see the CTRLINFO structure previously described);
  • set the dialog style to resizable if you want a resizable dialog. Warning: the non-target controls, placed on the dialog, should be managed by developer during the resizing phase (i.e. should be correctly repositioned);
  • define the class that manage the dialog, must derive from CSplitterDialog;
  • add a member variable for each target control and add the WM_INITDIALOG message map with Class Wizard, for example:
    CListCtrl m_ctrlLeft;
    CTreeCtrl m_ctrlRight;
  • in your OnInitDialog() override initialize CTRLINFO structure for each target control and call CSplitterDialog::InitDialog().

Thanks to Matteo Benzoni and Diego Perrotta


Download demo project - 33 Kb
Download source - 4 Kb


  • How to split the controls horizontally.

    Posted by Vishal Gundage on 10/13/2015 09:58am

    I want to split the controls horizontally. Instead of left and right, it needs to be top and bottom. I am new to MFC. How I can achieve this?

  • WndProc failure

    Posted by Legacy on 11/19/2002 08:00am

    Originally posted by: Vilmos Schnedarek

    There is a bug in the implementation of the WndProc hooking (NewWndProc). The old WndProc is saved in the m_MFCWndProc static variable. But what is happening if there are several different instances of this CSplitterDialog? In this case all these instances will use as the default WndProc the first one, which was saved into the m_MFCWndProc.
    This is totaly wrong, because every instance should use its window procedure.
    It can be corrected in two ways:

    1, make the m_MFCWndProc variable to be non-static and correct to code.

    2, delete everything related this window procedure hooking and create with the classwizard a message handler for the WM_SIZING then place there the following code:

    void CSplitterDialog::OnSizing(UINT fwSide, LPRECT pRect)
    // Verify that the controls size are correct: if are not correct set the value
    // to make it correct
    LPRECT rect = (LPRECT)pRect;
    if ( rect->right - rect->left - m_rectSplitter.right -
    (int)m_infoRight->m_nOffX - 8 < m_infoRight->m_sizeMin.cx )
    rect->right = m_infoRight->m_sizeMin.cx + rect->left +
    m_rectSplitter.right + m_infoRight->m_nOffX + 8;

    int max = max(
    m_infoLeft->m_sizeMin.cy + m_infoLeft->m_nOffY,
    m_infoRight->m_sizeMin.cy + m_infoRight->m_nOffY);
    if ( rect->bottom - rect->top - 8 < max )
    rect->bottom = max + rect->top + 8;


  • How can I set a based CView in a splitted window

    Posted by Legacy on 07/28/2001 07:00am

    Originally posted by: Mohamed KHADRAOUI

    I think that is very useful to give the possibility of attaching a CView based in a splitted area


  • Is there any way to split horizontally?

    Posted by Legacy on 01/24/2000 08:00am

    Originally posted by: Karen Gamble

    This is great. What I need is to be able to split horizontally. Actually I need 2 trees on the left, one on top of the other, and a report on the right the size of both trees.

  • Why not an arbitrary offset value for both top and bottom?

    Posted by Legacy on 01/04/2000 08:00am

    Originally posted by: Martin Amandusson

    The CSplitterDialog::InitDialog() takes two CTRLINFO structs as parameters. The CTRLINFO has a m_nHowY member that is used to tell wether the offset should displace the controls up or down. Why?

    It could in fact be useful to offset the splitter from top and bottom of the dialog at the same time. The CTRLINFO struct could be changed to hold the offsets from both top and bottom of the dialog.

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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