Click here to Skip to main content
Click here to Skip to main content

Windows 2000 Style Wizards

, 23 May 2000
Rate this:
Please Sign up or sign in to vote.
Create Windows 2000 style Wizards with white backgrounds
  • Download demo project - 107 Kb
  • Download source files - 7 Kb
  • Sample Image

    A Page from the Windows 2000 Style Wizard

    <!-- STEP 3. Add the article text.-->

    Introduction

    There are two main differences between the traditional MFC-CPropertySheet wizards and the Windows 2000 wizards:

    1. The Windows 2000 wizard has a white background.
    2. The "page" portion of the Windows 2000 wizard extends all the way to the edge of the dialog.
    The Microsoft GUI designers are fickle. I remember developing for Windows 3.1 and going through a lot of trouble to make grey dialog backgrounds instead of white backgrounds. Now we go through a lot of trouble to make white backgrounds instead of grey ones.

    This article presents two classes that allows you to create Windows 2000 style wizards relatively easily. Both classes are actually derived from CDialog, rather than CPropertySheet or CPropertyPage. The classes make use of some techniques presented in Zoran M.Todorovic's CodeProject article on stacked dialog boxes, however there are extensive code changes from Zoran's work.

    Another big advantage of this method of creating wizards is that you have total control over the placement and text of the wizard buttons, and you can even add other control outside of the wizard pages.

    The Classes

    The CNewWizDialog Class

    CNewWizDialog is derived from CDialog, but it is analagous to CPropertySheet when creating a standard MFC wizard. You create a dialog template with Back, Next, Cancel, and Finish buttons. You create a CNewWizDialog-derived class for your dialog resource.

    The CNewWizPage Class

    CNewWizPage is also derived from CDialog, however it is analagous to CPropertyPage when creating a standard MFC wizard. You create a dialog resource for each page of the wizard. You create a CNewWizPage-derived class for each wizard page.

    CNewWizDialog and CNewWizPage have very similar class interfaces to CPropertySheet and CPropertyPage respectively, so it should not be too difficult to convert your existing wizards to windows 2000 style wizards.

    Creating the Main Dialog

    1. In the Visual C++ resource editor, create a dialog template for the main wizard window. Be sure to give it Next, Back, Finish, and Cancel buttons. Buttons should have the following identifiers to match the standard MFC wizard:

    Cancel -- IDCANCEL
    Finish -- ID_WIZFINISH
    Back -- ID_WIZBACK
    Next -- ID_WIZNEXT

    Placing the Cancel and Finish Buttons

    In the traditional MFC wizards, The Finish button and the Cancel button are in the same position. One is hidden when the other is shown. If you want to mimic that behavior in these classes, it is simple enough, but you will have to make changes to the CNewWizDialog::EnableFinish(BOOL bEnable) function to show are hide the proper buttons.

    The Wizard Page Placeholder Control

    You will also need to give your main wizard dialog a frame rectangle (picture) control to act as a placeholder. If you make the frame "etched", you will get a nicer appearance. Your dialog should look something like the one below.

    Sample Image

    2. Using ClassWizard, create a CDialog-derived class for your dialog resource. Change the base class from CDialog to CNewWizDialog. It is very important that you also change your message map to call the base class CNewWizDialog instead of CDialog as shown below. Otherwise, your wizards buttons will not work!

    
    BEGIN_MESSAGE_MAP(CMasterDlg, CNewWizDialog)
    	//{{AFX_MSG_MAP(CMasterDlg)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    

    3. Override WM_INITDIALOG. Before calling the base class implementation of OnInitDialog, you must call CNewWizDialog::SetPlaceholderID() passing the control ID of the place holder rectangle as a parameter.

    Be sure to call the base class implementation CNewWizDialog::OnInitDialog and not CDialog::OnInitDialog as show below:

    
    BOOL CMasterDlg::OnInitDialog() 
    {
    	// you must call this function in OnInitDialog before you call the base class!
    	SetPlaceholderID(IDC_SHEETRECT);
    
    	// make sure to call the proper base class
    	CNewWizDialog::OnInitDialog();
    	
    	return TRUE;  // return TRUE unless you set the focus to a control
    	              // EXCEPTION: OCX Property Pages should return FALSE
    }
    
    

    Creating the Wizard Pages

    Follow the these steps for each page in your wizard.

    1. Create a dialog resource for the page. The dialog should have the following properties:

    • Child Style
    • No Border
    • Not Visible
    • Disabled
    Place the desired contols on the dialog.

    Note: You should make each wizard page the same size as the placeholder on your main wizard dialog.

    2. Use ClassWizard to create a CDialog-derived class for the dialog resource. Add any handlers for controls that you may require.

    3. Change the base class from CDialog to CNewWizPage. It is very important that you change the base classes for OnInitDialog, the constructor, and the message map.

    
    BEGIN_MESSAGE_MAP(CSetupPage, CNewWizPage)
    	//{{AFX_MSG_MAP(CSetupPage)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    
    4. Override any of the following functions to add functionality and data validation to your wizard page:
    
    // these functions behave the same as CPropertyPage
    virtual void CNewWizPage::OnCancel();
    virtual BOOL CNewWizPage::OnKillActive();
    virtual void CNewWizPage::OnSetActive();
    virtual BOOL CNewWizPage::OnQueryCancel( );
    virtual LRESULT CNewWizPage::OnWizardBack();
    virtual LRESULT CNewWizPage::OnWizardNext();
    virtual BOOL CNewWizPage::OnWizardFinish();
    
    

    Putting it All Together

    Once you have created all of your dialog classes as described above, you put the wizard together just as you would with a standard MFC CPropertySheet-based wizard. The only difference is that you must pass the ID of each pages's dialog resource to CNewWizDialog::AddPage().
    
    CMasterDlg Dlg(this);
    	
    CSetupPage SetupPage;
    CHardwarePage HardwarePage;
    CPrinterPage PrinterPage;
    	
    
    Dlg.AddPage(&HardwarePage, CHardwarePage::IDD);
    Dlg.AddPage(&SetupPage, CSetupPage::IDD);
    Dlg.AddPage(&PrinterPage, CPrinterPage::IDD);
    
    if (Dlg.DoModal() == ID_WIZFINISH)
    {
    	AfxMessageBox("Finished Wizard");
    }
    else
    {
    	AfxMessageBox("Cancelled Wizard");
    }
    
    

    Implementing the White Background

    One of the new features in the Windows 2000 style wizards is a white background. This is pretty easy to implement, and it is also easy to disable if you do not like it.

    1. In the declaration for CNewWizPage, we give the page it's own brush.

    class CNewWizPage : public CDialog
    {
    
    [snip]
    
    protected:
    	CBrush m_Brush;
    
    [snip]
    
    
    2. Override WM_INITDIALOG and create a white brush.
    
    BOOL CNewWizPage::OnInitDialog() 
    {
    	CDialog::OnInitDialog();
    	
    	// create the white brush for the background
    	m_Brush.CreateSolidBrush(RGB(255, 255, 255));
    
    	return TRUE;  // return TRUE unless you set the focus to a control
    	              // EXCEPTION: OCX Property Pages should return FALSE
    }
    
    

    3. Override the WM_CTLCOLOR message, and return the white brush and set text background colors as appropriate.

    
    HBRUSH CNewWizPage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    	
    	switch (nCtlColor)
    	{	   
    		case CTLCOLOR_STATIC:
    			pDC->SetTextColor(RGB(0, 0, 0));
    			pDC->SetBkColor(RGB(255,255,255));
    		case CTLCOLOR_EDIT:
    			pDC->SetTextColor(RGB(0, 0, 0));
    			pDC->SetBkColor(RGB(255,255,255));
    		case CTLCOLOR_LISTBOX:
    			pDC->SetTextColor(RGB(0, 0, 0));
    			pDC->SetBkColor(RGB(255,255,255));
    		case CTLCOLOR_SCROLLBAR:
    			pDC->SetTextColor(RGB(0, 0, 0));
    			pDC->SetBkColor(RGB(255,255,255));
    		case CTLCOLOR_BTN:
    			pDC->SetTextColor(RGB(0, 0, 0));
    			pDC->SetBkColor(RGB(255,255,255));
    		case CTLCOLOR_DLG:	    
    			return m_Brush;
    	}	
    	
    	// TODO: Return a different brush if the default is not desired
    	return m_Brush;
    }
    
    

    Potential Problems

    Many of the data validation functions for CNewWizPage return FALSE if the dialog data is not validated as desired. I did not spend a lot of time checking to make sure the classes worked as required when FALSE is returned from these functions. If you are doing a lot of data validation, be sure to test your wizard with invalid data so that it behaves as desired.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Robert Pittenger, MCPD-EAD
    President Starpoint Software Inc.
    United States United States
    Bob Pittenger is founder and President of Starpoint Software Inc. He holds a B.A. degree from Miami University, M.S. and Ph.D. degrees from Purdue University, and an MBA from Xavier University. He has been programming since 1993, starting with Windows application development in C++/MFC and moving to C# and .NET around 2005 and is a .NET Microsoft Certified Professional Developer.
     
    Bob is the author of two books:
    Billionaire: How the Ultra-Rich Built Their Fortunes Through Good and Evil and What You Can Learn from Them
    and
    Wealthonomics: The Most Important Economic and Financial Concepts that Can Make You Rich Fast.
    Visit http://www.billionairebook.net for more information.

    Comments and Discussions

     
    GeneralMy vote of 5 PinmemberRichchu10-Mar-13 21:41 
    GeneralMy vote of 5 Pinmemberbondukanthikiran22-Jul-10 20:32 
    GeneralPlease Help Me !! Pinmember"_$h@nky_"27-Nov-08 0:47 
    GeneralHelp me in design Windows Explorer in VC++ PinmemberVan Phuong Nguyen16-May-07 0:56 
    GeneralMemory Assertion PinmemberAarif Mohammad23-Apr-06 23:46 
    GeneralWindows 200 style already supported! PinmemberMark Werner18-Apr-05 8:50 
    GeneralRe: Windows 200 style already supported! PinmemberMark Werner18-Apr-05 9:03 
    QuestionHow do I change the master caption? Pinmemberbearded17-Dec-04 4:29 
    Generalpassing data PinmemberWendy Moore17-Oct-04 2:35 
    GeneralRe: passing data PinmemberJohn Simmons / outlaw programmer15-Nov-04 4:21 
    Generaldynamic combobox in a OCX Pinmemberedgar32528-Apr-04 21:41 
    GeneralSimple Querry Pinmemberspidey82023-Feb-04 3:43 
    GeneralRe: Simple Querry Pinmemberantadam25-Feb-04 11:03 
    QuestionHow do you automatically advance to the next page Pinmembervjairam30-Jan-04 4:09 
    I want to jump to next page without the user clicking the next button. e.g I am doing a wizard that checks if some components are installed on my thirdpage so when the operation completes I want to advance to the next page automatically which dispalys the result.
     
    Does anyone know how to do this.
    AnswerRe: How do you automatically advance to the next page Pinmembervjairam30-Jan-04 10:12 
    QuestionHow do I skip few pages ? Pinmembernewnick8-Jan-04 15:24 
    AnswerRe: How do I skip few pages ? Pinmembervjairam27-Jan-04 8:35 
    General&quot;Do not show this screen in future&quot; PinmemberNotProfessional22-Dec-03 10:32 
    GeneralBlank screen PinmemberMr. J.3-Dec-03 22:15 
    GeneralRe: Blank screen Pinmembervjairam30-Jan-04 4:11 
    GeneralRe: Blank screen PinmemberMr. J.30-Jan-04 5:45 
    GeneralRe: Blank screen Pinmembervjairam30-Jan-04 10:01 
    Questioncan't disable Finish button? Pinmembermichael thomas31-Aug-03 13:25 
    AnswerRe: can't disable Finish button? Pinmembermichael thomas31-Aug-03 13:33 
    QuestionModeless Wizard? PinmemberRabentochter5-Jul-02 23:13 
    AnswerRe: Modeless Wizard? PinmemberRabentochter7-Jul-02 23:26 
    GeneralRe: Modeless Wizard? PinmemberBaliDawg3-Dec-02 15:32 
    GeneralProblems transfering data back to main dialog PinmemberRobJones16-Nov-01 6:46 
    GeneralRe: Problems transfering data back to main dialog PinmemberBil Simser9-Apr-02 2:10 
    GeneralRe: Problems transfering data back to main dialog PinmemberAnonymous12-May-02 16:46 
    GeneralRe: Problems transfering data back to main dialog PinmemberBil Simser29-Jul-02 4:14 
    GeneralWM_CTLCOLOR PinmemberWes Jones6-Nov-01 11:45 
    GeneralRe: WM_CTLCOLOR PinmemberRavi Bhavnani6-Nov-01 12:08 
    GeneralComboBox problem! :-( PinmemberTDP4-Nov-01 6:43 
    GeneralRe: ComboBox problem! :-( PinmemberTDP4-Nov-01 8:17 
    Generalwhite buttons PinmemberThe Eclypse12-Oct-01 7:17 
    GeneralPush [return] on page PinmemberHarald Langner24-Jul-01 1:41 
    GeneralWhy don't U use CPropertySheetEx PinmemberCatalin Hatmanu16-May-01 9:28 
    GeneralRe: Why don't U use CPropertySheetEx PinmemberAndrew Peace24-Aug-01 12:27 
    GeneralAdded Functionality PinmemberJohn Simmons / outlaw programmer21-Dec-00 9:58 
    GeneralTabbing, Enter Key, Escape Key Pinsussjb12-Sep-00 5:28 
    GeneralRe: Tabbing, Enter Key, Escape Key PinmemberAnonymous24-Oct-01 5:39 
    GeneralKeyboard problems PinsussGerrit Gehnen31-Aug-00 6:25 
    GeneralRe: Keyboard problems Pinmemberehsiung30-May-11 7:05 
    GeneralFirst page doesn't draw correctly... PinsussMFC Student28-Aug-00 16:39 
    GeneralRe: First page doesn't draw correctly... Pinsussjb31-Aug-00 8:44 
    GeneralRe: First page doesn't draw correctly... PinsussBob Pittenger3-Sep-00 7:04 
    GeneralRe: First page doesn't draw correctly... PinsussMFC Student 3-Sep-00 11:26 
    GeneralAnother Painting Bug PinsussBob Pittenger7-Sep-00 4:17 
    GeneralThis could solve it PinmemberAl-Mutairi, Fayez22-Jul-01 2:08 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web03 | 2.8.140721.1 | Last Updated 24 May 2000
    Article Copyright 2000 by Robert Pittenger, MCPD-EAD
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid