Click here to Skip to main content
15,867,453 members
Articles / Desktop Programming / MFC

ZSplitter: Adding Automatic Splitting for Dialog Controls

Rate me:
Please Sign up or sign in to vote.
4.88/5 (14 votes)
28 May 2001 632.8K   6.4K   58   31
A set of classes that provide automatic adding necessary splitters in your dialogs

Introduction

The ZSplitterDlg and ZSplitter classes help you to add splitters to your dialog, property sheet or any other window. It splits your controls and makes them movable and resizeable. I think this way is better than "auto size" contol: it adds a "docking" opportunity. Moreover, one more control added that adds "auto size" option. Finally, you can integrate the ZSplitterDlg with a resizable dialog (for example, CResizableDialog by Paolo Messina).

Note that you shouldn't add anything to your resources and shouldn't describe the relations between controls. Just make the corresponding size and position of your controls and use the functions:

C++
void addControls(int count, bool connectVertical, ...);
void addControl(int id);

Demo project shows using these automatically added controls in CDialog, CPropertyPage, CView and CFormView classes.

Sample Image

Using the Class

The simplest way is to use the ZSplitterDlgImpl template. You should change:

  • the parent of your dialog or view class
  • the constructor implementation
  • the second parameter in BEGIN_MESSAGE_MAP macros, and
  • the "on init" function of your window
C++
// in header
class CTestDlg1 : public ZSplitterDlgImpl<CPropertyPage>

// in source
CTestDlg1::CTestDlg1() : /*...*/ ZSplitterDlgImpl<CPropertyPage>(CTestDlg1::IDD) {}

BEGIN_MESSAGE_MAP(CTestDlg1, ZSplitterDlgImpl<CPropertyPage>)
	//	...
END_MESSAGE_MAP()

BOOL CTestDlg1::OnInitDialog() 
{
	// ... and use addControl(s) function here
	init();
	// ...
}

The ZSplitterDlgImpl template has a second parameter (ZSplitter2 by default). ZSplitter2 is the implementation of a splitter control. It has a virtual function OnPaint() - and you can change its realisation to have different view of your control (see CMyView1 class in demo project).

The ZSplitterDlgImpl template helps you to implement splitter controls but you can use its base ZSplitterDlg class (look for CTestDlg2 class) in demo project.

I remade a little CResizableDialog with the permission of the author and you can use it with my splitters: use the ZSplitterDlgResizable class for this job (look for CDemoDlg class) in the demo project.

resizable sample

This is a sample of your dialog in resource editor:

in vc++ editor

And user can change it in such way in runtime.

after user manipulations

You should use the addControls or addControl functions to add one control to the "splitter set" or a group of controls: they will move together. This is an example which you have seen above.

C++
addControls(2,false,IDC_LIST6,IDC_LIST7);
addControls(2,true,IDC_LIST1,IDC_LIST8);
addControl(IDC_LIST9);
addControl(IDC_LIST2);
addControl(IDC_LIST3);
addControl(IDC_LIST4);
addControl(IDC_LIST5);

Moreover, you can manually add a ZSplitter class (the most common splitter controls) to a page. Look at the images and in the CTestDlg3 class of the demo project for details.

before moving

after moving

To Do List

I'd like to make the look (color, size, effects) of the splitter more presentable. So I want to get comments from you. First of all: is this technique useful to you?

Note

Make sure to check out my website which is more likely to have updates and betas:
http://www.zmike.net.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
Russian Federation Russian Federation
Mike has been programming in C/C++ for 11 years and Visual C++/MFC for 4 years. His background includes pure and applied mathematics, engineering and physics, and he is currently based in Moscow, Russia.

Comments and Discussions

 
QuestionThe compiler through not ah mistake too much Pin
37240589826-Aug-12 1:11
37240589826-Aug-12 1:11 
Questionthe demo can't compile under VS2008 Pin
pj220_200620-May-12 19:23
pj220_200620-May-12 19:23 
GeneralMy vote of 5 Pin
zhangyongf27-Dec-10 16:31
zhangyongf27-Dec-10 16:31 
GeneralMyView1.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CView::messageMap" Pin
Gertzog26-Nov-07 14:54
Gertzog26-Nov-07 14:54 
Generalcompiling problems in 2003 .NET Pin
picazo7-Aug-05 14:39
picazo7-Aug-05 14:39 
GeneralRe: compiling problems in 2003 .NET Pin
gnovice10-Oct-05 18:47
gnovice10-Oct-05 18:47 
GeneralRe: compiling problems in 2003 .NET Pin
picazo11-Oct-05 4:23
picazo11-Oct-05 4:23 
QuestionCan not compile under VC7 Pin
Satervalley13-Aug-02 17:12
Satervalley13-Aug-02 17:12 
AnswerRe: Can not compile under VC7 Pin
chend30-Oct-02 22:19
chend30-Oct-02 22:19 
GeneralFit a dialog in a View of a Window Pin
17-Apr-02 9:16
suss17-Apr-02 9:16 
GeneralRe: Fit a dialog in a View of a Window Pin
CapsuleDweller9-May-02 1:44
CapsuleDweller9-May-02 1:44 
GeneralZSplit in dynamic dialog Pin
Emanuele17-Apr-02 8:18
Emanuele17-Apr-02 8:18 
GeneralRe: ZSplit in dynamic dialog Pin
Mike Melnikov24-Jul-02 1:50
Mike Melnikov24-Jul-02 1:50 
Generalpragma warning Pin
Jean-Louis Guenego6-Aug-01 0:37
Jean-Louis Guenego6-Aug-01 0:37 
May be this can help some people testing the ZSplitter demo
(that was not obvious for me Blush | :O )

To avoid warning in your project, you just have to do like in the demo project
add to your stdafx.h:
#pragma warning (disable : 4786)
#pragma warning (disable : 4355)


Thanks for all your work Mike.

Jean-Louis
GeneralSplitter Pin
Pascal Cayrol18-May-01 3:00
Pascal Cayrol18-May-01 3:00 
GeneralRe: Splitter Pin
Pascal Cayrol18-May-01 4:14
Pascal Cayrol18-May-01 4:14 
GeneralRe: Splitter Pin
Mike Melnikov30-May-01 1:27
Mike Melnikov30-May-01 1:27 
GeneralNow it works with resizable dialog. Pin
Mike Melnikov6-Mar-01 23:17
Mike Melnikov6-Mar-01 23:17 
Questionwork with resizable dialog? Pin
philip andrew1-Mar-01 13:04
philip andrew1-Mar-01 13:04 
AnswerRe: work with resizable dialog? Pin
Mike Melnikov2-Mar-01 5:48
Mike Melnikov2-Mar-01 5:48 
AnswerRe: work with resizable dialog? Pin
Mike Melnikov6-Mar-01 23:25
Mike Melnikov6-Mar-01 23:25 
GeneralRe: work with resizable dialog? Pin
philip andrew13-Mar-01 10:46
philip andrew13-Mar-01 10:46 
GeneralExample As Member tab crashes Pin
26-Feb-01 1:49
suss26-Feb-01 1:49 
GeneralRe: Example As Member tab crashes Pin
Mike Melnikov26-Feb-01 5:33
Mike Melnikov26-Feb-01 5:33 
GeneralI got the same problem. Pin
26-Feb-01 13:13
suss26-Feb-01 13:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.