Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

Understanding the Win32 Sequence of Events

This section gives a brief overview of the structure and sequence of events down at the Win32 level. Unless you like a challenge and have loads of spare time, you won't actually need to implement a property sheet using the direct API calls and structures. Instead, you will use the MFC (or Active Template Library) wrapper classes (discussed in the previous sections), which greatly simplify the process. However, it is worth a brief discussion of these events to understand the processes underlying the wrapper classes.

Before the property sheet is displayed, each page is added to a PROPSHEETHEADER structure in memory as a pointer to a PROPSHEETPAGE structure and corresponding window handle.

When the property sheet is displayed initially, the first page is displayed and sent a WM_INITDIALOG message. If the user then selects another page, the first page is hidden and the new dialog box is displayed and sent a WM_INITDIALOG message. If the user then reselects a previously displayed (but now hidden) page, the reselected page is redisplayed, but no WM_INITDIALOG message is sent.

This sequence of events sent by Windows indicates that each of the dialog boxes comprising the pages of the property sheet is modeless, with the overall modality controlled by the parent property sheet itself.

Except for the initial page, the dialog boxes for each page are never created unless the user specifically selects the tab for that page. However, once created, the individual dialog boxes stay created until the property sheet itself is destroyed. The created dialog boxes are merely hidden when their tab isn't currently active. You can see this in action by using the Visual Studio Spy++ IDE tool to study the window's hierarchy while a property sheet (such as the Internet control panel applet) is displayed.

Obviously, there will be times when you'll need to validate the details on a particular page before allowing the user to select another page. You can perform this validation from the currently active page when the tab control sends it a PSN_KILLACTIVE notification message. To keep the current page active, you can set a TRUE message result value in response to the notification. Alternatively, a FALSE message result allows the selection to continue resulting in a PSN_SETACTIVE notification being sent to the newly activated page. You can use the PSN_SETACTIVE notification to initialize or reinitialize any controls in the newly activated tab.

After a user clicks the OK or Apply property sheet button, a PSN_APPLY message is sent to each of the property pages to let you take whatever appropriate action is required for each page. When the OK or Cancel button is pressed, the property sheet is closed and all the property page and property sheet windows are destroyed. However, the convention is that Apply should implement the changes specified by the modified control settings without closing the property sheet.

Share ThisShare This

Informit Network