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

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds