FunctionX - Practical Learning Logo

Visual C++ Spoiled in .NET

 

Overview

Like a property sheet, a wizard can be made of one or more pages (it is possible but not practical to have a wizard with only one page). A wizard you have just created may have the Back, Next, Cancel, and Help buttons:

To exploit it, the user would click a Next or Back buttons. The Next button allows the user to access the page that succeeds the current one. The Back button implements the opposite, allowing the user to access the previous page. If the wizard is equipped with a Cancel button, the user can close and dismiss it at any time. This, by default allows you to ignore anything the user did on the wizard.

As with anything else in the world or programming, you should make your wizard intuitive and friendly. For example, on the first page, since there is no reason for the user to access the previous page, you should disable it. On the other hand, when the user gets to the last page, since there is no succeeding page, there is no need for a Next button. Consequently, you should replace it with a Finish button. Fortunately, the display of these buttons is not the most difficult thing to manage on a wizard.

Buttons Configuration

In order to decide what button(s) should be available when a particular page is accessed, generate its CPropertyPage::OnSetActive() event. Its syntax is:

virtual BOOL OnSetActive( );

This event fires when a page of your choice is accessed, allowing you to do what you want on the wizard page. One of the actions you can take when a page displays is to decide what button(s) should be displayed on the wizard. The buttons of a wizard are managed through the CPropertySheet::SetWizardButtons() method. Its syntax is:

void SetWizardButtons(DWORD dwFlags);

The dwFlags argument is a constant or a combination of values that defines the buttons to display. The possible values are PSWIZB_BACK for the Back button, PSWIZB_NEXT for the Next button, PSWIZB_FINISH for the Finish button, and PSWIZB_DISABLEDFINISH to disable Finish button disabled.

On the first page, to display the Next button while disabling the Back button, you can pass only the PSWIZB_NEXT value. Here is an example:

BOOL CPersonalInfo::OnSetActive()
{
	// TODO: Add your specialized code here and/or call the base class
	CPropertySheet *EmplSheet = reinterpret_cast<CPropertySheet *>(GetParent());

	EmplSheet->SetWizardButtons(PSWIZB_NEXT);

	return CPropertyPage::OnSetActive();
}

On the last page, you should display the Back and the Finish buttons. Here is an example:

BOOL CEmplSurvey::OnSetActive()
{
	// TODO: Add your specialized code here and/or call the base class
	CPropertySheet *EmplSheet = reinterpret_cast<CPropertySheet *>(GetParent());

	EmplSheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);

	return CPropertyPage::OnSetActive();
}

All pages between the first and the last should display the Back and the Next buttons, unless you have a reason to do otherwise. This would be done as follows:

BOOL CEducExperience::OnSetActive()
{
	// TODO: Add your specialized code here and/or call the base class
	CPropertySheet *EmplSheet = reinterpret_cast<CPropertySheet *>(GetParent());

	EmplSheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);

	return CPropertyPage::OnSetActive();
}

You can also add your own button(s) to the wizard, you can use the same approach we saw earlier. Here is an example:

CExoWizardSheet::OnInitDialog()
{
	BOOL bResult = CPropertySheet::OnInitDialog();

	CButton *btnWhatever = new CButton;

	BtnWhatever->Create(“Whatever”, WS_CHILD | WS_VISIBLE,
	Crect(10, 362, 126, 385), this, 0x122);

	Return bResult;
}
 

Copyright © 2003-2005 FunctionX, Inc.