Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Resizable Property Sheet/Wizard using CDialogResize

, 12 Mar 2007
Make Property Sheet/Wizards resizable without much modification.
resizablepropertysheet.zip
ResizablePropertySheet.exe
watermark.bmp
wihu.bmp
resizablepropertysheet_demo.zip
watermark.bmp
wihu.bmp
ResizablePropertySheet.exe
resizablepropertysheet_src.zip
resizeablepropertysheetsrc.zip
#include "stdafx.h"

#include "resource.h"
#include "ResizablePropertySheet.h"

CAppModule _Module;

/* ------------------------------------------------------------------------- */

class CResizablePropertyPage0 : public CResizablePropertyPageImpl<CResizablePropertyPage0> {
private:
	CFont DlgTitleFont;
public:
	enum { IDD = IDD_0 };

	CResizablePropertyPage0(ATL::_U_STRINGorID title = (LPCTSTR) NULL, bool IsExterior = false, bool EnableDoubleBuffer = false) : CResizablePropertyPageImpl<CResizablePropertyPage0>(title, IsExterior, EnableDoubleBuffer) {
	}
	
	BOOL OnSetActive() {
		GetPropertySheet().SetWizardButtons(PSWIZB_NEXT);
		return TRUE;
	}

	LRESULT OnInitDialog(HWND hWnd, LPARAM lParam) {
		CFontHandle DlgFont = GetFont();
		CClientDC dcScreen(NULL);
		
		LOGFONT LogFont = {0};
		DlgFont.GetLogFont(&LogFont);
		_tcscpy(LogFont.lfFaceName, _T("verdana bold"));

		LogFont.lfWeight = FW_BOLD;
		LogFont.lfHeight = -::MulDiv(12, dcScreen.GetDeviceCaps(LOGPIXELSY), 72);
		
		DlgTitleFont.CreateFontIndirect(&LogFont);
		GetDlgItem(IDC_LBL_TITLE).SetFont(DlgTitleFont);

		SetMsgHandled(FALSE);
		return TRUE;
	}

	BOOL OnQueryCancel() {
		if (MessageBox(_T("Do you really want to close this wizard?"), _T("Closing this wizard"), MB_ICONINFORMATION | MB_YESNO | MB_DEFBUTTON2) == IDYES)
			return FALSE;
		else
			return TRUE;
	}

	BEGIN_MSG_MAP_EX(CResizablePropertyPageImpl)
		MSG_WM_INITDIALOG(OnInitDialog)
		CHAIN_MSG_MAP(CResizablePropertyPageImpl<CResizablePropertyPage0>)
		CHAIN_MSG_MAP(CDialogResize<CResizablePropertyPage0>)
	END_MSG_MAP()
	BEGIN_DLGRESIZE_MAP(CResizablePropertyPage0)
		DLGRESIZE_CONTROL(IDC_STATIC_NEXT, DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_LBL_WELCOME, DLSZ_SIZE_X)
	END_DLGRESIZE_MAP()
};

class CResizablePropertyPage1 : public CResizablePropertyPageImpl<CResizablePropertyPage1> {
public:
	enum { IDD = IDD_1 };

	CResizablePropertyPage1(ATL::_U_STRINGorID title = (LPCTSTR) NULL, bool IsExterior = false, bool EnableDoubleBuffer = false) : CResizablePropertyPageImpl<CResizablePropertyPage1>(title, IsExterior, EnableDoubleBuffer) {
	}
	
	BOOL OnSetActive() {
		GetPropertySheet().SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
		return TRUE;
	}
	
	BOOL OnQueryCancel() {
		if (MessageBox(_T("Do you really want to close this wizard?"), _T("Closing this wizard"), MB_ICONINFORMATION | MB_YESNO | MB_DEFBUTTON2) == IDYES)
			return FALSE;
		else
			return TRUE;
	}

	BEGIN_MSG_MAP_EX(CResizablePropertyPageImpl)
		CHAIN_MSG_MAP(CResizablePropertyPageImpl<CResizablePropertyPage1>)
		CHAIN_MSG_MAP(CDialogResize<CResizablePropertyPage1>)
	END_MSG_MAP()
	BEGIN_DLGRESIZE_MAP(CResizablePropertyPage1)
		DLGRESIZE_CONTROL(IDC_LBL_1, DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_RADIO1, DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_RADIO2, DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_LBL_2, DLSZ_MOVE_X | DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_EDIT1, DLSZ_SIZE_X)
		DLGRESIZE_CONTROL(IDC_EDIT2, DLSZ_SIZE_X)
	END_DLGRESIZE_MAP()
};

class CResizablePropertyPage2 : public CResizablePropertyPageImpl<CResizablePropertyPage2> {
public:
	enum { IDD = IDD_2 };
 
	CResizablePropertyPage2(ATL::_U_STRINGorID title = (LPCTSTR) NULL, bool IsExterior = false, bool EnableDoubleBuffer = false) : CResizablePropertyPageImpl<CResizablePropertyPage2 >(title, IsExterior, EnableDoubleBuffer) {
	}
	
	int OnSetActive() {
		GetPropertySheet().SetWizardButtons(PSWIZB_FINISH);
		CListBox(GetDlgItem(IDC_LIST1)).AddString(_T("1. Item 1 installed successfully"));
		CListBox(GetDlgItem(IDC_LIST1)).AddString(_T("2. Item 2 installed successfully"));
		CListBox(GetDlgItem(IDC_LIST1)).AddString(_T("No errors"));
		return TRUE;
	}

	BOOL OnQueryCancel() {
		if (MessageBox(_T("Do you really want to close this wizard?"), _T("Closing this wizard"), MB_ICONINFORMATION | MB_YESNO | MB_DEFBUTTON2) == IDYES)
			return FALSE;
		else
			return TRUE;
	}

	INT_PTR OnWizardFinish() {
		::MessageBox(GetParent(), _T("You selected the finish button"), 0, MB_ICONINFORMATION | MB_TASKMODAL);
		return FALSE;
	}

	BEGIN_MSG_MAP_EX(CResizablePropertyPageImpl)
		CHAIN_MSG_MAP(CResizablePropertyPageImpl<CResizablePropertyPage2>)
		CHAIN_MSG_MAP(CDialogResize<CResizablePropertyPage2>)
	END_MSG_MAP()
	BEGIN_DLGRESIZE_MAP(CResizablePropertyPage2)
		DLGRESIZE_CONTROL(IDC_LIST1, DLSZ_SIZE_X | DLSZ_SIZE_Y)
		DLGRESIZE_CONTROL(IDC_CHECK1, DLSZ_MOVE_Y)
	END_DLGRESIZE_MAP()
};

/* ----- My user defined property sheet ----- */

class CMyPropertySheet : public CResizablePropertySheetImpl<CMyPropertySheet> {
private:
	bool HasCentered;
public:
	CMyPropertySheet(ATL::_U_STRINGorID title = (LPCTSTR)NULL, UINT uStartPage = 0, HWND hWndParent = NULL, bool EnableDoubleBuffering = false, bool IsWizard = false)
	: CResizablePropertySheetImpl<CMyPropertySheet>(title, uStartPage, hWndParent, EnableDoubleBuffering, IsWizard),
	HasCentered (false) {
	}

	void OnShowWindow(bool, int) {
		CenterWindow(GetDesktopWindow());
		SetMsgHandled(FALSE);
	}

	BEGIN_MSG_MAP_EX(CMyPropertySheet)
		MSG_WM_SHOWWINDOW(OnShowWindow)
		CHAIN_MSG_MAP(CResizablePropertySheetImpl<CMyPropertySheet>)
	END_MSG_MAP()
private:
};

int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT) {

	CMessageLoop theLoop;
	CMyPropertySheet Sheet((LPCTSTR) NULL);
	_Module.AddMessageLoop(&theLoop);

	Sheet.SetHeader((LPCTSTR) IDB_HEADER);
	Sheet.SetWatermark((LPCTSTR) IDB_WATERMARK);
	
	CResizablePropertyPage0 pgWelcome((LPCTSTR) NULL, true);
	CResizablePropertyPage1 pgMiddle;
	CResizablePropertyPage2 pgComplete((LPCTSTR) NULL, true);
	
	pgMiddle.SetHeaderTitle(_T("Header title of this wizard page 1"));
	pgMiddle.SetHeaderSubTitle(_T("This is the sub header title of this page"));

	Sheet.AddPage (pgWelcome);
	Sheet.AddPage (pgMiddle);
	Sheet.AddPage (pgComplete);

	/* just test double buffering here */
	pgComplete.EnableDoubleBuffering();

	if (Sheet.Create(GetDesktopWindow()) == NULL) {
		ATLTRACE(_T("Main dialog creation failed!\n"));
		return 0;
	}
	
	Sheet.ShowWindow(nCmdShow);
	
	int nRet = theLoop.Run();
	
	/* If "Finish" button is pressed, Property Sheet window handle will not be destroyed */
	if (Sheet.IsWindow()) {
		/* Get real dialog result */
		nRet = Sheet.GetResult();
		Sheet.DestroyWindow();
	}

	_Module.RemoveMessageLoop();
	return nRet;
}

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) {
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_WIN95_CLASSES | ICC_TAB_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();
	::CoUninitialize();

	return nRet;
}

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

Share

About the Author

bkausbk

Germany Germany
Hobby: system programing (operating system and hardware)
Prefered languages are x86 assembler, c and c++.
Currently student of applied computer science at university of applied sciences Bingen (Germany)

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150302.1 | Last Updated 12 Mar 2007
Article Copyright 2005 by bkausbk
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid