#include "stdafx.h"
#include "resource.h"
#include "ResizablePropertySheet.h"
#define __MODELESS__ // Modeless window
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_EX(CResizablePropertyPage0)
DLGRESIZE_CONTROL_EX(IDC_STATIC_NEXT, DLSZ_MOVE_Y)
DLGRESIZE_CONTROL_EX(IDC_LBL_WELCOME, DLSZ_SIZE_X)
END_DLGRESIZE_MAP_EX()
};
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() {
CListViewCtrl List(GetDlgItem(IDC_LIST1));
for (int i = 0; i < 100; i++) {
TCHAR Text[64] = {0};
_stprintf(Text, TEXT("Testitem number %d"), i);
List.AddItem(0, 0, Text);
}
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_EX(CResizablePropertyPage1)
DLGRESIZE_CONTROL_EX(IDC_LBL_1, DLSZ_MOVE_Y)
DLGRESIZE_CONTROL_EX(IDC_RADIO1, DLSZ_MOVE_Y)
DLGRESIZE_CONTROL_EX(IDC_RADIO2, DLSZ_MOVE_Y)
DLGRESIZE_CONTROL_EX(IDC_LBL_2, DLSZ_MOVE_X | DLSZ_MOVE_Y)
DLGRESIZE_CONTROL_EX(IDC_EDIT1, DLSZ_SIZE_X)
DLGRESIZE_CONTROL_EX(IDC_EDIT2, DLSZ_SIZE_X)
DLGRESIZE_CONTROL_EX(IDC_LIST1, DLSZ_SIZE_X | DLSZ_SIZE_Y)
END_DLGRESIZE_MAP_EX()
};
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_EX(CResizablePropertyPage2)
DLGRESIZE_CONTROL_EX(IDC_LIST1, DLSZ_SIZE_X | DLSZ_SIZE_Y)
DLGRESIZE_CONTROL_EX(IDC_CHECK1, DLSZ_MOVE_Y)
END_DLGRESIZE_MAP_EX()
};
/* ----- 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();
int nRet = 0;
#ifdef __MODELESS__
if (Sheet.Create(GetDesktopWindow()) == NULL) {
ATLTRACE(_T("Main dialog creation failed!\n"));
return 0;
}
Sheet.ShowWindow(nCmdShow);
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();
}
#else
Sheet.DoModal(GetDesktopWindow());
#endif
_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;
}