Click here to Skip to main content
12,826,247 members (26,146 online)
Click here to Skip to main content
Add your own
alternative version


47 bookmarked
Posted 17 Nov 1999

Child Dialog (Sub Forms)

, 17 Nov 1999
Rate this:
Please Sign up or sign in to vote.
A simple class for handling Child Dialogs within a dialog or property sheet.




A simple class for handling Child Dialogs within a dialog or property sheet. These Child Dialogs can be changed on the fly, much like subforms. It's a simple task really, but I got tired of programming everything every time :-(

Step 1. Design one or several 'Subdialogs'. Make sure to set the Style to Child and to tick the property 'Control'.

Step 2. Design a Parent Dialog. To make things easier, I add a static control for easier positioning of the child dialogs (normally I use a group frame).

Step 3. Generate for all dialogs, their classes.

Step 4. Add the files SubFormCollection.cpp and SubFormCollection.h to your project.

Step 5. Create an object of the class CSubFormCollection to the parent dialog.

   CSubFormCollection m_SubForms;

Step 6. In the OnInitDialog() method of the parent class, add the code below:

   CRect r;
   // get the position for the subforms
   // if the positioning is absolute use this, else the next line
   //    m_SubForms.SetRelPos(r);
   // centers the subdialog within the static IDC_SUBFORM_FRAME
   m_SubForms.CreateSubForm(IDD_SUBFORM1,this); // create the sub forms
   m_SubForms.ShowSubForm(); // show the first one

Step 7. To switch between the subdialogs, use the code below:


Now the big work starts...


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

Daniel Zuppinger
Chief Technology Officer
Switzerland Switzerland
Professional IT developer since 1983. First projects with Cobol, then Pascal, Modula2, C and since Visual C++ 1.0 also with C++. Works since 1986 as Consultant, between 1990 and 2008 for Infobrain in Switzerland, currently employed by enValue (also Switzerland).
Current field is the project management and development of software for Bank applications.
Married, two daughters, Hobbies : Paragliding, Orienteering, Mountainbiking, Photography

You may also be interested in...

Comments and Discussions

GeneralHandling Windows messages Pin
Matt Soler17-Apr-00 12:31
sussMatt Soler17-Apr-00 12:31 
GeneralRe: Handling Windows messages Pin
Daniel Zuppinger17-Apr-00 20:22
sussDaniel Zuppinger17-Apr-00 20:22 
Sorry, but my code contains a error and I have not had the time to fix it. The problem is that you need to construct the CDialogs with new and then pass them to my class. e.g. :
(Code taken from a response I got from Jason Wilden)

bool CSubDlgCollection::CreateSubForm(CDialog *pDlg,UINT id, CWnd* pParentWnd)
if (pDlg == NULL) return(false);

// exit and tell the world about it
AddForm(pDlg); // Add it to the internal table

// Now create the dialog


The destructor also needs some modification:

// Free all sub forms on destruction
for (int i = 0; i <= m_Forms.GetUpperBound(); i++) {
CDialog* pDlg = m_Forms.GetAt(i);

The modified class is then used as follows :

CDlgNewProjectGroups *pDlg = new CDlgNewProjectGroups;

pDlg->m_bIncludeAllGroups = TRUE;
m_SubForms.CreateSubForm(pDlg,IDD_NEW_PROJECT_GROUPS,this); // create the sub forms

CDlgNewProjectSettings *pDlg2 = new CDlgNewProjectSettings;
m_SubForms.CreateSubForm (pDlg2,IDD_NEW_PROJECT_SETTINGS,this); // create
the sub forms

m_SubForms.ShowSubForm(); // show the first one

Regards Danie
GeneralRe: Handling Windows messages Pin
Bo Su27-Jul-00 16:39
sussBo Su27-Jul-00 16:39 
GeneralRe: Handling Windows messages Pin
ehomebuilder5-Feb-04 17:25
memberehomebuilder5-Feb-04 17:25 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170326.1 | Last Updated 18 Nov 1999
Article Copyright 1999 by Daniel Zuppinger
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid