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

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds