Introduction

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 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
(GetDlgItem(IDC_SUBFORM_FRAME))->GetWindowRect(&r);
// 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.SetCenterPos(r);
m_SubForms.CreateSubForm(IDD_SUBFORM1,this); // create the sub forms
m_SubForms.CreateSubForm(IDD_SUBFORM2,this);
m_SubForms.CreateSubForm(IDD_SUBFORM3,this);
m_SubForms.CreateSubForm(IDD_SUBFORM4,this);
m_SubForms.ShowSubForm(); // show the first one
//

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

// m_SubForms.ShowSubForm(index_of_subform);
//

Now the big work starts...

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.

Share

About the Author

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

This is a great class, however it hangs when radio buttons are added to the parent (hosting) dialog. All other control types seem to work, but wouldn’t you know --- I need radio buttons for my design. I’m not sure if anyone else has seen this, but any assistance in resolving the anomaly be greatly appreciated.

TO REPRODUCE (in demo project):
1. Place two radio buttons in the IDD_TEST (parent/host) dialog.
2. Set the first radio button’s group property.
3. Rebuild and run.
4. Click either radio button.
5. App hangs somewhere in subsequent Windows’ message logic, after drawing the selected radio button.

...steven

P.S. Yes, I’ve included the latest modifications noted in the threads, but maybe I'm overlooking something.

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)