I'm just learning the Win32 API using C, and I needed to add wizard to my application. This is the first time I've ever done this, so I'm sure there's multiple things wrong with this code.
I've been studying the MSDN website, and I've based this implementation on my interpretation of the examples and explanations offered there. What am I missing here? The wizard buttons aren't changing, and clicking Next on the last page of the wizard does nothing.
The only way to close the wizard is to press the cancel button. I'm lost. Any help is greatly appreciated!
#include <Windows.h>
#include <WinUser.h>
#include <richedit.h>
#include <prsht.h>
#include <commctrl.h>
#include "Resource.h"
//declarations
BOOL CALLBACK PrpWelcomeProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK PrpEnvironmentVarsProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK PrpToolChainVarsProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK PrpEditorBehaviorProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK PrpFinishProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam);
int CreateProjectDialog(HWND Parent)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
PROPSHEETPAGE psp = {sizeof (psp)};
HPROPSHEETPAGE hPrP[5];
// Setup the Welcome page
psp.hInstance = hInstance;
psp.dwFlags = PSP_HIDEHEADER;
psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_LARGE_WELCOME);
psp.pfnDlgProc = PrpWelcomeProc;
psp.lParam = (LPARAM)NULL;
hPrP[0] = CreatePropertySheetPage(&psp);
// Setup the Environment Variables page
psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
psp.pszHeaderTitle = TEXT("Environment Variables");
psp.pszHeaderSubTitle = TEXT("Use these options to setup the default environment for your OS project.");
psp.pszTemplate = MAKEINTRESOURCE(IDD_FORMVIEW_ENV_VARIABLES);
psp.pfnDlgProc = PrpEnvironmentVarsProc;
psp.lParam = (LPARAM)NULL;
hPrP[1] = CreatePropertySheetPage(&psp);
// Setup the Toolchain Options page
psp.pszHeaderTitle = TEXT("Toolchain Settings");
psp.pszHeaderSubTitle = TEXT("Use these options to setup your toolchain.");
psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_LARGE);
psp.pfnDlgProc = PrpToolChainVarsProc;
psp.lParam = (LPARAM)NULL;
hPrP[2] = CreatePropertySheetPage(&psp);
// Setup the Editor Behavior page
psp.pszHeaderTitle = TEXT("Editor Behavior");
psp.pszHeaderSubTitle = TEXT("Use these options to customize the editor.");
psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_LARGE_EDITOR);
psp.pfnDlgProc = PrpEditorBehaviorProc;
psp.lParam = (LPARAM)NULL;
hPrP[3] = CreatePropertySheetPage(&psp);
// Setup the Finish Page
psp.dwFlags = PSP_HIDEHEADER;
psp.pszHeaderTitle = NULL;
psp.pszHeaderSubTitle = NULL;
psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_FINISH);
psp.pfnDlgProc = PrpFinishProc;
psp.lParam = (LPARAM)NULL;
hPrP[4] = CreatePropertySheetPage(&psp);
// Setup the Propage Header to define the Wizard
// The Watermark Bitmap and the Header Bitmap need to be created
PROPSHEETHEADER pHeader = { sizeof(pHeader) };
pHeader.dwFlags = PSH_WIZARD97 | PSH_WATERMARK;
pHeader.hInstance = hInstance;
pHeader.hwndParent = Parent;
pHeader.nPages = &psp;
pHeader.nStartPage = 0;
pHeader.nPages = 5;
pHeader.pszbmWatermark = MAKEINTRESOURCE(IDB_BITMAP1);
pHeader.phpage = hPrP;
// Launch the Wizard
PropertySheet(&pHeader);
return 0;
}
//Dialog Procedures for all of the Dialogs in the Create Project Wizard
BOOL CALLBACK PrpWelcomeProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam)
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (Message)
{
case WM_INITDIALOG:
return FALSE;
case WM_NOTIFY:
switch (pnmh->code)
{
case PSN_SETACTIVE:
PropSheet_SetWizButtons(hDialog, PSWIZB_NEXT);
return FALSE;
}
}
return FALSE;
}
BOOL CALLBACK PrpEnvironmentVarsProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam)
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (Message)
{
case WM_INITDIALOG:
return FALSE;
case WM_NOTIFY:
switch (pnmh->code)
{
case PSN_SETACTIVE:
PropSheet_SetWizButtons(hDialog, PSWIZB_NEXT | PSWIZB_BACK | PSWIZB_CANCEL);
return FALSE;
}
}
return FALSE;
}
BOOL CALLBACK PrpToolChainVarsProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam)
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (Message)
{
case WM_INITDIALOG:
return FALSE;
case WM_NOTIFY:
switch (pnmh->code)
{
case PSN_SETACTIVE:
PropSheet_SetWizButtons(hDialog, PSWIZB_NEXT | PSWIZB_BACK | PSWIZB_CANCEL);
return FALSE;
}
}
return FALSE;
}
BOOL CALLBACK PrpEditorBehaviorProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam)
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (Message)
{
case WM_INITDIALOG:
return FALSE;
case WM_NOTIFY:
;
switch (pnmh->code)
{
case PSN_SETACTIVE:
PropSheet_SetWizButtons(hDialog, PSWIZB_NEXT | PSWIZB_BACK | PSWIZB_CANCEL);
return FALSE;
}
}
return FALSE;
}
BOOL CALLBACK PrpFinishProc(HWND hDialog, UINT Message, WPARAM wParam, LPARAM lParam)
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (Message)
{
case WM_INITDIALOG:
return FALSE;
case WM_NOTIFY:
switch (pnmh->code)
{
case PSN_SETACTIVE:
PropSheet_SetWizButtons(hDialog, PSWIZB_BACK | PSWIZB_CANCEL | PSWIZB_FINISH);
PropSheet_SetFinishText(hDialog, TEXT("Finish"));
return FALSE;
}
case WM_DESTROY:
return FALSE;
}
return FALSE;
}
As Raymond Chen said: hDlg is "Handle to the property sheet".
For the handle to the wizard itself, please call GetParent(hwnd)
.