Click here to Skip to main content
15,894,546 members
Articles / Desktop Programming / MFC

Layout Manager for Dialogs, Formviews, DialogBars and PropertyPages

Rate me:
Please Sign up or sign in to vote.
4.92/5 (91 votes)
4 Aug 2000 975.1K   11.9K   320  
A framework to provide automatic layout control for dialogs and forms
// LayoutManagerView.cpp : Implementierung der Klasse CLayoutManagerView
//

#include "stdafx.h"
#include "LayoutManager.h"

#include "LayoutManagerDoc.h"
#include "LayoutManagerView.h"

#include "MyDialog.h"
#include "TabDialog.h"
#include "CtrlDialog.h"
#include "PropPage1.h"

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


/////////////////////////////////////////////////////////////////////////////
// CLayoutManagerView

IMPLEMENT_DYNCREATE(CLayoutManagerView, ETSLayoutFormView)

BEGIN_MESSAGE_MAP(CLayoutManagerView, ETSLayoutFormView)
	//{{AFX_MSG_MAP(CLayoutManagerView)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLayoutManagerView Konstruktion/Destruktion

CLayoutManagerView::CLayoutManagerView()
	: ETSLayoutFormView(CLayoutManagerView::IDD)
{
	//{{AFX_DATA_INIT(CLayoutManagerView)
	//}}AFX_DATA_INIT

}

CLayoutManagerView::~CLayoutManagerView()
{
}

void CLayoutManagerView::DoDataExchange(CDataExchange* pDX)
{
	ETSLayoutFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLayoutManagerView)
		// HINWEIS: Der Klassenassistent f�gt an dieser Stelle DDX- und DDV-Aufrufe ein
	//}}AFX_DATA_MAP
}

BOOL CLayoutManagerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// ZU ERLEDIGEN: �ndern Sie hier die Fensterklasse oder das Erscheinungsbild, indem Sie
	//  CREATESTRUCT cs modifizieren.

	return ETSLayoutFormView::PreCreateWindow(cs);
}

void CLayoutManagerView::OnInitialUpdate()
{
	ETSLayoutFormView::OnInitialUpdate();
	ResizeParentToFit();

	/* DialogMgr: Add this: */

	// We want to have a disign like this
	//  ---------------------------
	// |  ----------   ----------  |
	// | | Button 1 | | Button 2 | | Pane1
	// |  ----------   ----------  |
	//  ---------------------------
	//  ---------------------------
	// |  ----------   ----------  |
	// | | Button 3 | | Button 4 | | Pane2
	// |  ----------   ----------  |
	//  ---------------------------
	//  ---------------------------
	// |  ----------   ----------  |
	// | | Button 5 | | Button 6 | | Pane3
	// |  ----------   ----------  |
	//  ---------------------------
	//  ---------------------------
	// |  ----------   ----------  |
	// | | Button 7 | | Button 8 | | Pane4
	// |  ----------   ----------  |
	//  ---------------------------

	UpdateLayout(

		pane(VERTICAL)
		<<	(pane(HORIZONTAL) << item(IDC_BUTTON1) << item(IDC_BUTTON2))
		<<	(pane(HORIZONTAL) << item(IDC_BUTTON3) << item(IDC_BUTTON4))
		<<	(pane(HORIZONTAL) << item(IDC_BUTTON5) << item(IDC_BUTTON6))
		<<	(pane(HORIZONTAL) << item(IDC_BUTTON7) << item(IDC_BUTTON8))

	);

	/************************/
}

/////////////////////////////////////////////////////////////////////////////
// CLayoutManagerView Diagnose

#ifdef _DEBUG
void CLayoutManagerView::AssertValid() const
{
	ETSLayoutFormView::AssertValid();
}

void CLayoutManagerView::Dump(CDumpContext& dc) const
{
	ETSLayoutFormView::Dump(dc);
}

CLayoutManagerDoc* CLayoutManagerView::GetDocument() // Die endg�ltige (nicht zur Fehlersuche kompilierte) Version ist Inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLayoutManagerDoc)));
	return (CLayoutManagerDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLayoutManagerView Nachrichten-Handler

void CLayoutManagerView::OnButton1() 
{
	CMyDialog dlg;
	dlg.DoModal();
}

void CLayoutManagerView::OnButton2() 
{
	CTabDialog dlg;
	dlg.DoModal();
}

void CLayoutManagerView::OnButton3() 
{
	CCtrlDialog dlg;
	dlg.DoModal();
}

void CLayoutManagerView::OnButton4() 
{
	ETSLayoutPropertySheet* pModelessPropSheet = new ETSLayoutPropertySheet(_T("Modeless Property Sheet"));
	pModelessPropSheet->AddPage( new CPropPage1 );
	pModelessPropSheet->AddPage( new CPropPage2 );
	pModelessPropSheet->SetAutoDestroy();
	pModelessPropSheet->SetAutoDestroyPages();
	pModelessPropSheet->Create(this);
}

void CLayoutManagerView::OnButton5() 
{
	ETSLayoutPropertySheet sheet(_T("PropertySheet Test"));

	CPropPage1 page1;
	CPropPage2 page2;

	sheet.AddPage(&page1);
	sheet.AddPage(&page2);

	sheet.DoModal();
}

void CLayoutManagerView::OnButton6() 
{
	ETSLayoutPropertySheet sheet(_T("PropertySheet Test"));
//	sheet.m_psh.dwFlags |= PSH_WIZARDHASFINISH;

	CPropPage1 page1;
	CPropPage2 page2;

	sheet.AddPage(&page1);
	sheet.AddPage(&page2);

	sheet.SetWizardMode();

	sheet.DoModal();	
}

void CLayoutManagerView::OnButton7() 
{
	CMyDialogHorz dlg;
	dlg.DoModal();
}

void CLayoutManagerView::OnButton8() 
{
	CMyDialogVert dlg;
	dlg.DoModal();

}

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
Web Developer
Germany Germany
independant software developer from Germany.
author of Euraconf, an isdn/pabx management software

Programmer since 1991, c/c++/java, started with professional games development, now mainly network, telecommunication and internet stuff

Comments and Discussions