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

  • Do you know where your data is? Consumer cloud-based file sharing services store your sensitive company data on servers outside of your control, outside of your policy and regulatory guidelines – maybe even outside your country – and not managed by you. The potential for data leakage, security breaches, and harm to your business is enormous. Download this white paper to learn about file sync and share alternatives that allow you to manage and protect your sensitive data while integrating and …

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds