Download Special Edition Using Visual C++ 6

Transcript
Special Edition Using Visual C++ 6 -- Ch 12 -- Property Pages and Sheets
6. To display the property sheet, call the property sheet's constructor and then call the property
sheet's DoModal() member function, just as you would with a dialog box.
After you write your application and define the resources and classes that represent the property sheet (or
sheets--you can have more than one), you need a way to enable users to display the property sheet when
it's needed. In Property Sheet Demo, this is done by associating a menu item with a message-response
function. However you handle the command to display the property sheet, the process of creating the
property sheet is the same. First, you must call the property sheet class's constructor, which Property
Sheet Demo does like this:
CPropSheet propSheet("Property Sheet", this, 0);
Here, the program creates an instance of the CPropSheet class. This instance (or object) is called
propSheet. The three arguments are the property sheet's title string, a pointer to the parent window
(which, in this case, is the view window), and the zero-based index of the first page to display. Because
the property pages are created in the property sheet's constructor, creating the property sheet also creates
the property pages.
After you create the property sheet object, you can initialize the data members that hold the values of the
property page's controls, which Property Sheet Demo does like this:
propSheet.m_page1.m_edit = m_edit;
propSheet.m_page2.m_checkbox = m_check;
Now it's time to display the property sheet, which you do just as though it were a dialog box, by calling
the property sheet's DoModal() member function:
int result = propSheet.DoModal();
DoModal() doesn't take any arguments, but it does return a value indicating which button users clicked to
exit the property sheet. In a property sheet or dialog box, you'll usually want to process the information
entered into the controls only if users clicked OK, which is indicated by a return value of IDOK. If users
exit the property sheet by clicking the Cancel button, the changes are ignored and the view or document
member variables aren't updated.
Changing Property Sheets to Wizards
Here's a piece of information that surprises most people: A wizard is just a special property sheet. Instead
of tabbed pages on each sheet that allow users to fill in the information in any order or to skip certain
pages entirely, a wizard has Back, Next, and Finish buttons to move users through a process in a certain
order. This forced sequence makes wizards terrific for guiding your application's users through the steps
needed to complete a complex task. You've already seen how AppWizard in Visual C++ makes it easy to
start a new project. You can create your own wizards suited to whatever application you want to build. In
the following sections, you'll see how easy it is to convert a property sheet to a wizard.
http://www.pbs.mcp.com/ebooks/0789715392/ch12/ch12.htm (9 of 13) [7/29/1999 3:49:16 PM]