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

  • Ever-increasing workloads and the challenge of containing costs leave companies conflicted by the need for increased processing capacity while limiting physical expansion. Migration to HP's new generation of increased-density rack-and-blade servers can address growing demands for compute capacity while reducing costly sprawl. Sponsored by: HP and Intel® Xeon® processors Intel, the Intel logo, and Xeon Inside are trademarks of Intel Corporation in the U.S. and/or other countries. HP is the sponsor …

  • The rapid evolution of enterprise storage technologies, combined with external forces, like the explosion of big data, can cause Linux® and server administrators to play catch-up when it comes to storage. Running a bunch of monolithic storage devices and proprietary, disconnected technologies forces administrators to spend valuable time creating and managing complex solutions. To reduce complexity and enable rapid deployment of new technologies and applications, server administrators need a single open …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds