Resizeable Wizard97 style Wizards






2.55/5 (7 votes)
Property sheet and page classes for resizeable Wizard97 style Wizards
Background
A year or so ago I implemented a wizard for the calibration of positions of arrays of acoustic beacons on the seabed, as part of our Pharos acoustic positioning application.
After doing a little research, I proposed that we use the (then relatively
new) Wizard97 style to implement it, to give it more visual impact. To this
end, I implemented MFC classes for a wizard sheet (CWizard
) and
page (CWizardPage
). Although most of the pages were conventional,
one of them contained a Chart view (with an associated document) within a frame
window, complete with two toolbars:
This page introduced a problem. To make it useable it really needed to be bigger - or, even better, resizeable. Unfortunately, at the time we had higher priorities so resizing stayed firmly on the "to do" list.
The breakthrough came with the publication of Herbert Menke's CResizeCtrl on Code Project, which we started using to support resizeable dialogs and property pages elsewhere within the project. In due course, the inevitable happened, and we implemented another Wizard.
Unfortunately, when we integrated CResizeCtrl
into the new wizard,
the Wizard97 style appeared to be incompatible with resizing - the watermark
and header bitmaps failed to paint correctly. As a result, the new wizard was
implemented with the Wizard97 features disabled (we reasoned that we could always
paint them ourselves if we couldn't find a solution later).
I've now finally got around to doing just that. Using code from Joerg Koenig's
CBitmapDialog
class, CWizard
now paints the header bitmaps, and CWizardPage
the watermarks. I had to make some minor changes to CResizeCtrl
to accommodate wizard pages with header bitmaps, but other than that it worked
pretty much first time.
To demonstrate these classes I've incorporated them into the Microsoft Wizard97
sample (renamed as CNGWizard
and CNGWizardPage
respectively).
The demo project compiles quite happily at warning Level 4; ANSI and Unicode builds are supported.
Usage
Before implementing your own Wizard97 classes, it's worth reading the Wizard97 Specification in the Visual C++ Help (its also available on the MSDN website), which contains useful guidelines for implementing wizards using the Wizard97 style.
Implementing a wizard using these classes is pretty straightforward:
Derive your wizard sheet class from
CNGWizard
, and your page classes fromCNGWizardPage
Add an OnInitDialog() override to each page and add the page's controls to the resizer (see Herbert Menke's CResizeCtrl article for full details on how to do this)
Set CNGWizard::m_bResizeable in the constructor of your wizard sheet class if you want your wizard to be resizeable
Set CNGWizard::m_bShowFinishAlways in the constructor of your wizard sheet class if you want the Next and Finish buttons in the wizard to both be visible at all times (this can be useful in some wizards)
Initialise your wizard sheet by specifying the watermark and header bitmaps, together with their display styles (centred, tiled or stretched for the watermark, and tiled or stretched for the header)
Create your pages and add them to the wizard.
CNGWizard
will configure the pages for you as they are added.Note that each page will be (briefly) activated as it is added to allow the resizer to initialise properly. A consequence of this is that
OnInitDialog()
andOnSetActive()
overrides in your pages will be called earlier than they may expect. To prevent this causing problems,CNGWizardPage
has anIsInitialising()
method which derived classes can use to determine whether this is the case:BOOL CInterior1::OnInitDialog() { CInterior1_BASE::OnInitDialog(); if (IsResizeable()) { // Add: id, left, top, width, height m_Resizer.Add( IDC_LIST1, 0, 0, 100, 100 ); m_Resizer.Add( IDC_STATIC_DESC, 100, 0, 0, 100 ); m_Resizer.Add( IDC_BUTTON1, 100, 100, 0, 0 ); } return TRUE; } BOOL CInterior1::OnSetActive() { if (!IsInitialising()) { EnableWizardButtons(PSWIZB_BACK | PSWIZB_NEXT, TRUE); } return CInterior1_BASE::OnSetActive(); }
System Requirements and Limitations
Because these classes are based upon the
CPropertySheetEx
andCPropertyPageEx
classes introduced with Visual C++ 6.0, I'm afraid this code will not work with Visual C++ 5.0.On older systems (pre-WinMe/2000) the use of Wizard97 may require an upgrade to the common controls library (comctl32.dll), since version 5.80 or later is required to use Wizard97 controls. If your system requires this update, you can download an installer (50comupd.exe) for the update from the Microsoft web site at http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp.
According to the Microsoft documentation on Wizard97, Wizard97 controls will not work correctly on Windows 95 systems. However, when I ran this sample on a Win95 machine the only problem I could see was that static controls on pages which had watermarks didn't display correctly (presumably because transparency doesn't work for static controls on Win95). Apart from that minor problem, the wizard worked just fine and was perfectly legible.
In order to correctly repaint the watermark and header bitmaps when the wizard is resized the windows must be created with the
CS_HREDRAW
andCS_VREDRAW
window class styles. Although this should be done by registering a custom window class,CNGWizard::OnInitDialog()
currently just modifies the global style using the Platform SDK functionSetClassLong()
.
Finally...
...a bit of a plug: if you want to see an example of these classes in action, check out my Resource ID Organiser Add-In for Visual C++ which uses these classes to implement a Wizard for renumbering resource symbols.
If you have any comments, suggestions, bug reports etc. please feel free to email me at andy.metcalfe@lineone.net.