CWizardPage - an MFC Convenience Class for Wizard Dialogs

Environment: VC++ 6

In one of my last projects I had to use several wizard dialogs, meaning that I had CPropertyPage objects within a CPropertySheet and set the style to wizard mode before calling DoModal, e.g.

   dlg.SetWizardMode();
   if ( dlg.DoModal() == ID_WIZFINISH )
      ; //do something appropriate

It felt quite painful to override every page's OnSetActive() method in order to show or hide the BACK, NEXT, FINISH and other buttons, so I did put all this into a tiny yet handy class. The class, CWizardPage, derives from CPropertyPage and is quite easy to use: Simply design your property page's dialog resource as you always do and create a CPropertyPage derived class with VC++'s class wizard.

Now include the header via

   #include "WizardPage.h"

into your class's header file.

Replace every occurance of the word "CPropertyPage" with "CWizardPage".

Now supply your page's constructor with a parameter ( SheetPos posPositionOnSheet = Middle ) that designates the page's position in the wizard and change the call to the base class constructor to my class's like in

   CYourPage::CYourPage( SheetPos posPositionOnSheet ) :
      CWizardPage( posPositionOnSheet, CYourPage::IDD )
   {}

Note: You HAVE to supply the default value as MFC requires a standard constructor for your class. At the place where you use your wizard you have to supply this parameter when constructing your pages like in

   CYourPage pageFirst( CWizardPage::First );
   CYourPage pageSecond( CWizardPage::Middle );
   CYourPage pageThird( CWizardPage::Middle );
   CYourPage pageFourth( CWizardPage::Last );

where the value CWizardPage::Only means that you have a degenerated wizard with only one page, i.e. the Back button is grayed and the Finish button is shown.

"En passant" my class corrects a known MFC bug by calling UpdateData() when you click the Finish button.

I hope that some of you find this class useful. If so, I'd like to hear about your experience with it as well as any bug reports and suggestions for future versions.

Downloads

Download WizardPageTest sample project - 48 Kb
Download CWizardPage source code - 3 Kb


Comments

  • classwizard

    Posted by Legacy on 04/24/2003 12:00am

    Originally posted by: hot3dx

    yep uh, ok - cool!
    

    Reply
  • Very Good!!

    Posted by Legacy on 11/22/2002 12:00am

    Originally posted by: Good!!

    Very Good!!

    Reply
  • Very helpful.

    Posted by Legacy on 11/18/2002 12:00am

    Originally posted by: chubun

    I found the class very easy to use. Just like you said, it simplifies the step to setup the buttons for the propery dialog. Btw, just wonder is there a copyright on this class. Thanks.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

  • On-demand Event Event Date: March 27, 2014 Teams need to deliver quality software faster and need integrated agile planning, task tracking, source control, auto deploy with continuous builds and a configurable process to adapt to the way you work. Rational Team Concert and DevOps Services (JazzHub) have everything you need to build great software, integrated seamlessly together right out of the box or available immediately in the cloud. And with the Rational Team Concert Client, you can connect your …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds