Splitter Dialog

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


  • Your own double turn on adidas

    Posted by Updatatweda on 05/05/2013 10:00pm

    J [url=http://www.adidaskutuja.com/]アディダス スニーカー[/url] jnUgh NafDud HtpHjm ZolI [url=http://www.adidaskutuja.com/adidas-originals-c-4.html]アディダス ランニングシューズ[/url] akIrhIwe EkhWxwVbnQ [url=http://www.adidaskutuja.com/adidas-superstar-c-2.html]アディダス シューズ[/url] hp MarOso [url=http://www.adidaskutuja.com/jeremy-scott-c-5.html]アディダス 通販[/url]CweFza LmgMiw

  • WndProc failure

    Posted by Legacy on 11/19/2002 12: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 12: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 12: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 12: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.

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

Top White Papers and Webcasts

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Event Date: April 15, 2014 The ability to effectively set sales goals, assign quotas and territories, bring new people on board and quickly make adjustments to the sales force is often crucial to success--and to the field experience! But for sales operations leaders, managing the administrative processes, systems, data and various departments to get it all right can often be difficult, inefficient and manually intensive. Register for this webinar and learn how you can: Align sales goals, quotas and …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds