Click here to Skip to main content
15,887,337 members
Articles / Desktop Programming / MFC

Child Dialog (Sub Forms)

Rate me:
Please Sign up or sign in to vote.
4.27/5 (8 votes)
17 Nov 1999 143.3K   3.7K   48  
A simple class for handling Child Dialogs within a dialog or property sheet.
// TestDlg.cpp: Implementierungsdatei
//

#include "stdafx.h"
#include "ChildDlgTest.h"
#include "TestDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CTestDlg 


CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDlg)
		// HINWEIS: Der Klassen-Assistent f�gt hier Elementinitialisierung ein
	//}}AFX_DATA_INIT
}


void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlg)
	DDX_Control(pDX, IDC_COMBO1, m_Combo);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlg)
	ON_WM_SHOWWINDOW()
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen f�r Nachrichten CTestDlg 

BOOL CTestDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Zus�tzliche Initialisierung hier einf�gen

    m_Combo.SetCurSel(0);


    //#### initialize sub forms
    CRect r;
    (GetDlgItem(IDC_SUBFORM_FRAME))->GetWindowRect(&r); // get the position for the subforms
    //    m_SubForms.SetRelPos(r);  // if the positioning is absolute
    m_SubForms.SetCenterPos(r);     // if the subdialog needs to be centered
    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
    //#### end initialize sub forms


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zur�ckgeben
}


void CTestDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
    
    // TODO: Code f�r die Behandlungsroutine f�r Nachrichten hier einf�gen
}


void CTestDlg::OnSelchangeCombo1() 
{
    //#### method to change between sub forms
    //#### here a combobox in the main dialog is used
	m_SubForms.ShowSubForm(((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel());	
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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
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++ and today C#. Works since 1986 as Consultant, between 1990 and 2008 for Infobrain in Switzerland, from 2008 until 2013 for enValue (also Switzerland) and currently working for Comfone (Bern, Switzerland).

Married, two grown-up daughters, Hobbies : Paragliding, Orienteering, Mountainbiking, Photography

Comments and Discussions