65.9K
CodeProject is changing. Read more.
Home

Child Dialog (Sub Forms)

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.58/5 (9 votes)

Nov 18, 1999

viewsIcon

147683

downloadIcon

3756

A simple class for handling Child Dialogs within a dialog or property sheet.

ChildDlg1.gif

ChildDlg1.gif

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 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
    (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...

OSZAR »