PAGES.CPP

/*------------------------------------------------*\ 
*
*Copyright (c) 1997 Microsoft Corporation
*
*Module Name:
*
*pages.cpp
*
*Abstract:
*
*Property sheet page routines
*
\*------------------------------------------------*/


#include "stdafx.h"
#include "wpprov.h"
#include "wppobj.h"
#include "pages.h"
#include "resource.h"
#include "util.h"


const PAGEINFO g_pPageInfo[NUM_PAGES] =
{
{ Page0DlgProc, IDD_PAGE_0 },
{ Page1DlgProc, IDD_PAGE_1 }
};


HRESULT MakeBold(HWND hwnd, BOOL fSize, LONG lfWeight)
{
HRESULThr = ERROR_SUCCESS;
HFONThfont = NULL;
HFONThnewfont = NULL;
LOGFONT*plogfont = NULL;

if (!hwnd) goto MakeBoldExit;

hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
if (!hfont)
{
hr = ERROR_GEN_FAILURE;
goto MakeBoldExit;
}

plogfont = (LOGFONT*)malloc(sizeof(LOGFONT));
if (!plogfont)
{
hr = ERROR_NOT_ENOUGH_MEMORY;
goto MakeBoldExit;
}

if (!GetObject(hfont,sizeof(LOGFONT),(LPVOID)plogfont))
{
hr = ERROR_GEN_FAILURE;
goto MakeBoldExit;
}

if (abs(plogfont->lfHeight) < 24 && fSize)
{
plogfont->lfHeight = plogfont->lfHeight + (plogfont->lfHeight / 4);
}

plogfont->lfWeight = (int) lfWeight;

if (!(hnewfont = CreateFontIndirect(plogfont)))
{
hr = ERROR_GEN_FAILURE;
goto MakeBoldExit;
}

SendMessage(hwnd,WM_SETFONT,(WPARAM)hnewfont,MAKELPARAM(TRUE,0));

free(plogfont);

MakeBoldExit:

return (HRESULT_FROM_WIN32(hr));
}


HRESULT ReleaseBold(HWND hwnd)
{
HFONT hfont = NULL;

hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
if (hfont) DeleteObject(hfont);
return ERROR_SUCCESS;
}


BOOL CALLBACK Page0DlgProc(HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
CComObject<CWPProvider>*pWPP;

switch (uMsg) {

case WM_INITDIALOG:
{
// get propsheet page struct passed in
LPPROPSHEETPAGE lpsp = (LPPROPSHEETPAGE) lParam;

// fetch our private page info from propsheet struct
CComObject<CWPProvider> *pWPP = (CComObject<CWPProvider> *) lpsp->lParam;

// store pointer to private page info in window data for later
SetWindowLong(hDlg, DWL_USER, (LPARAM) pWPP);

// Enable Back and Next buttons
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT | PSWIZB_BACK);

// Make the title text bold
MakeBold(GetDlgItem(hDlg, IDC_PAGE_TITLE), TRUE, FW_BOLD);

return(TRUE);
}

break;// WM_INITDIALOG

case WM_NOTIFY:
{
// get pointer to private page data out of window data
NMHDR*lpnm = (NMHDR *) lParam;

pWPP = (CComObject<CWPProvider> *) GetWindowLong(hDlg,DWL_USER);

switch (lpnm->code)
{
case PSN_SETACTIVE:

// Enable Back and Next buttons
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT | PSWIZB_BACK);
SetWindowLong(hDlg, DWL_MSGRESULT, 0);

break;

case PSN_WIZNEXT:

SetWindowLong(hDlg, DWL_MSGRESULT, g_pPageInfo[1].uDlgID);
break;

case PSN_WIZBACK:

SetWindowLong(hDlg, DWL_MSGRESULT, pWPP->m_dwPageBeforeMe);
break;

case PSN_WIZFINISH:
case PSN_HELP:

break;

case PSN_QUERYCANCEL:

{
charsTitle[MAX_PATH];
charsMsg[MAX_MSG_LEN];
BOOLfQuit;

LoadString(GetModuleHandle(DLL_FILENAME_A), IDS_APPNAME, sTitle, sizeof(sTitle));
LoadString(GetModuleHandle(DLL_FILENAME_A), IDS_WARN_CANCEL, sMsg, sizeof(sMsg));
fQuit = (MessageBox(hDlg,
sMsg,
sTitle,
MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2)
== IDYES);

SetWindowLong(hDlg, DWL_MSGRESULT, !fQuit);
return(TRUE);
}

break;
}

return(TRUE); // return value is ignored and can be anything
}

break;

case WM_COMMAND:
{
// get pointer to private page data out of window data
pWPP = (CComObject<CWPProvider> *) GetWindowLong(hDlg, DWL_USER);

WORD wNotifyCode, wId;
HWND hwndCtl;

wNotifyCode = HIWORD(wParam); // notification code
wId = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control
}

break;

case WM_DESTROY:

ReleaseBold(GetDlgItem(hDlg, IDC_PAGE_TITLE));
break;

}

return(FALSE);
}


BOOL CALLBACK Page1DlgProc(HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
CComObject<CWPProvider>*pWPP;

switch (uMsg) {

case WM_INITDIALOG:
{
// get propsheet page struct passed in
LPPROPSHEETPAGE lpsp = (LPPROPSHEETPAGE) lParam;

// fetch our private page info from propsheet struct
CComObject<CWPProvider> *pWPP = (CComObject<CWPProvider> *) lpsp->lParam;

// store pointer to private page info in window data for later
SetWindowLong(hDlg, DWL_USER, (LPARAM) pWPP);

// Enable Back and Next buttons
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT | PSWIZB_BACK);

// Make the title text bold
MakeBold(GetDlgItem(hDlg, IDC_PAGE_TITLE), TRUE, FW_BOLD);

return(TRUE);
}

break;// WM_INITDIALOG

case WM_NOTIFY:
{
// get pointer to private page data out of window data
NMHDR*lpnm = (NMHDR *) lParam;

pWPP = (CComObject<CWPProvider> *) GetWindowLong(hDlg,DWL_USER);

switch (lpnm->code)
{
case PSN_SETACTIVE:

// Enable Back and Next buttons
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT | PSWIZB_BACK);
SetWindowLong(hDlg, DWL_MSGRESULT, 0);

break;

case PSN_WIZNEXT:

SetWindowLong(hDlg, DWL_MSGRESULT, pWPP->m_dwPageAfterMe);
break;

case PSN_WIZBACK:

SetWindowLong(hDlg, DWL_MSGRESULT, g_pPageInfo[0].uDlgID);
break;

case PSN_WIZFINISH:
case PSN_HELP:

break;

case PSN_QUERYCANCEL:

{
charsTitle[MAX_PATH];
charsMsg[MAX_MSG_LEN];
BOOLfQuit;

LoadString(GetModuleHandle(DLL_FILENAME_A), IDS_APPNAME, sTitle, sizeof(sTitle));
LoadString(GetModuleHandle(DLL_FILENAME_A), IDS_WARN_CANCEL, sMsg, sizeof(sMsg));
fQuit = (MessageBox(hDlg,
sMsg,
sTitle,
MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2)
== IDYES);

SetWindowLong(hDlg, DWL_MSGRESULT, !fQuit);
return(TRUE);
}

break;
}

return(TRUE); // return value is ignored and can be anything
}

break;

case WM_COMMAND:
{
// get pointer to private page data out of window data
pWPP = (CComObject<CWPProvider> *) GetWindowLong(hDlg, DWL_USER);

WORD wNotifyCode, wId;
HWND hwndCtl;

wNotifyCode = HIWORD(wParam); // notification code
wId = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control
}

break;

case WM_DESTROY:

ReleaseBold(GetDlgItem(hDlg, IDC_PAGE_TITLE));
break;

}

return(FALSE);
}