Click here to Skip to main content
Click here to Skip to main content

ZSplitter : adding automatic splitting for dialog controls

By , 28 May 2001
 

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 add "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:

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 ot view class,
  • the constructor implementation,
  • the second parameter in BEGIN_MESSAGE_MAP macros, and
  • the "on init" function of your window.
// 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 spliter control. It has a virtual function OnPaint() - and you can change it's 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 seen above

  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 the my web site 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

About the Author

Mike Melnikov
Web Developer
Russian Federation Russian Federation
Member
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionThe compiler through not ah mistake too muchmember37240589826 Aug '12 - 1:11 
Hi,You this example is very good ,but The compiler through not Laugh | :laugh: ah mistake too much
Questionthe demo can't compile under VS2008memberpj220_200620 May '12 - 19:23 
1>------ 已启动生成: 项目: splitter, 配置: Debug Win32 ------ 1>正在编译... 1>StdAfx.cpp 1> WINVER not defined. Defaulting to 0x0600 (Windows Vista) 1>正在编译... 1>DemoDlg.cpp 1>e:\zsplitter_demo\splitter\zsplitterdlg.h(162) : error C2039: “_GetBaseMessageMap”: 不是“ZSplitterDlgImpl”的成员...
GeneralMy vote of 5memberzhangyongf27 Dec '10 - 16:31 
nice
GeneralMyView1.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CView::messageMap"memberGertzog26 Nov '07 - 14:54 
Hi there!   I have linking the example project with Visual Studio 2003 and have got 10 linker error messages:   MyView1.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CView::messageMap" (?messageMap@CView@@1UAFX_MSGMAP@@B) splitter.obj :...
Generalcompiling problems in 2003 .NETmemberpicazo7 Aug '05 - 14:39 
Hi Mike,   First of all, great tool. However, I can't seem to be able to build it in VS 2003.NET. When I try, I get the following error   ZSplitterDlg.h(158): error C2039: '_GetBaseMessageMap' : is not a member of 'ZSplitterDlgImpl'   It appears several times.  ...
GeneralRe: compiling problems in 2003 .NETmembergnovice10 Oct '05 - 18:47 
Hello Genaro   I wanted an answer to the same problem (compile problem): Found a related solution on: http://www.codeguru.com/Cpp/Cpp/cpp_mfc/templates/comments.php/c4099/?thread=2597[^]   Note that the documented solution has a small error in it: word "template" needs to be...
GeneralRe: compiling problems in 2003 .NETmemberpicazo11 Oct '05 - 4:23 
Thank you very much. I had already found the solution too... maybe I should have posted it.   Regards,   ----------------- Genaro
QuestionCan not compile under VC7memberSatervalley13 Aug '02 - 17:12 
Hi,your code can not compile under VC7,because the macros DECLARE_MESSAGE_MAP & BEGIN_MESSAGE_MAP are not the same as they in VC6.
AnswerRe: Can not compile under VC7memberchend30 Oct '02 - 22:19 
Hi Do u have a source code for VC7 ?   Thanks, Chen
GeneralFit a dialog in a View of a WindowmemberAnonymous17 Apr '02 - 9:16 
  I have a fixed size dialog.   I have list of tree items on the left view and when I click one of the nodes I want to display the dialog in the right view   with the condition that if the size of the dialog is bigger than the view then I'll have to provide the scroll bars...
GeneralRe: Fit a dialog in a View of a WindowmemberCapsuleDweller9 May '02 - 1:44 
I'd like to[ ] do something similar, a browse tree on the left with dialogs on the right.   I'm guessing you meen modeless rather than modal. Modal would mean only one dialog activated from the browse tree at any one time.   The root of the problem is how to have a dialog...
GeneralZSplit in dynamic dialogmemberEmanuele17 Apr '02 - 8:18 
Hi Mike, I have downloaded ZSplit source from www.codeproject.com and I have tried to use it in my project. I have to use it in a dynamic dialog, that I have implemented by   IMPLEMENT_DYNAMIC(MyDlg, ZSplitterDlgResizable);   when I try to compile that code, I got this error:...
GeneralRe: ZSplit in dynamic dialogmemberMike Melnikov24 Jul '02 - 1:50 
Hi   add IMPLEMENT_DYNAMIC(CResizableDialog,CDialog); and change IMPLEMENT_DYNAMIC(MyDlg, ZSplitterDlgResizable); to IMPLEMENT_DYNAMIC(MyDlg, CResizableDialog);   Mike
Generalpragma warningmemberJean-Louis Guenego6 Aug '01 - 0:37 
May be this can help some people testing the ZSplitter demo (that was not obvious for me )   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...
GeneralSplittermemberPascal Cayrol18 May '01 - 3:00 
hi I'd like to split a window and in a pane, I want to put some control like buttons or editbox ?   How can I do ?   Thanks !   Pascal   Pascal Cayrol
GeneralRe: SplittermemberPascal Cayrol18 May '01 - 4:14 
I'd like split a Client Area in two View.   In the first one, I'd like to put List Control and in the other, I'd like to put button and editbox.   How can I put button in a CView ? Is it possible ?     Thanks a lot !   Pascal Cayrol
GeneralRe: SplittermemberMike Melnikov30 May '01 - 1:27 
Hi check new version of my article http://codeproject.com/splitter/zsplitter.asp   Mike
GeneralNow it works with resizable dialog.memberMike Melnikov6 Mar '01 - 23:17 
Hi   Yes I made 2 improvements 1. CResizableDialog now supported you can use ZSplitterDlgResizable I've added 1 function and make 1 function virtual in CResizableDialog.cpp CResizableDialog.h   2.new template class ZSplitterDlgImpl : public T, protected ZSplitterDlg added...
Questionwork with resizable dialog?memberphilip andrew1 Mar '01 - 13:04 
Hi,   This is fantastic, I would really like to see it work with the resizable dialog class at http://www.codeproject.com/dialog/resizabledialog.asp as this would solve a great problem for me.   Cheers, Philip
AnswerRe: work with resizable dialog?memberMike Melnikov2 Mar '01 - 5:48 
Hi, Philip   Thank you.   I think I'll do it.   Although I think I have to add one virtual function to CResizableDialog.   I think I'll give my answer in several days.   Mike.
AnswerRe: work with resizable dialog?memberMike Melnikov6 Mar '01 - 23:25 
Hi Philip   Yes you can use them together.   Thank you for your persistence (I don't want to work a lot on ZSplitters).   please check my full answer   Mike
GeneralRe: work with resizable dialog?memberphilip andrew13 Mar '01 - 10:46 
Thanks Mike It works good for me. There are some errors when resizing, such as when dragging smaller then larger the box doesn't stay in the same place at all times but otherwise it is great mate !
GeneralExample As Member tab crashesmemberAnonymous26 Feb '01 - 1:49 
Select the Example As Member tab on Win2000 Pro and "The memory could not be written" and bang!
GeneralRe: Example As Member tab crashesmemberMike Melnikov26 Feb '01 - 5:33 
I've tested it on one Win2000 machine - it work's.   If it is not too difficult: can you run debug version of that example on your computer?   Mike.
GeneralI got the same problem.memberAnonymous26 Feb '01 - 13:13 
I got the same problem on Win2000 Pro.

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 29 May 2001
Article Copyright 2001 by Mike Melnikov
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid