Splitter Dialog


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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

This article was originally published on December 17th, 1999

Most Popular Programming Stories

More for Developers

RSS Feeds

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