The general procedure for creating a modal property sheet is given in the
following steps:
- For each page of the property sheet, add a dialog template to the
application’s .rc file that defines the page’s controls. The caption statement
is used to specify the title that will appear on the tab at the top of the page.
The dialog templates for property sheet pages should not include OK and Cancel
buttons as conventional dialog templates do, because the property sheet provides
these buttons on its own.
- For each page of the property sheet, derive a dialog-like class from CPropertyPage adding member variables for the page’s controls. ClassWizard will
write the DoDataExchange() function which is needed to transfer data between the
member variables and the controls and optionally to validate the user’s input.
- Derive a class from CPropertySheet. In the property sheet class, instantiate
property page objects for each of the property pages that we constructed in step
2. Use CPropertySheet::AddPage() to add the pages to the property sheet in the
order in which we want them to appear.
- In the application’s handler function that opens the property box, construct
an object of our property sheet class. The first parameter (the caption of the
property sheet) to the three parameter constructor; the last two parameters have
default values. The constructor is overloaded and the first parameter can be a
string or the ID of a string.
Like dialog boxes, the property sheet is opened with the call DoModal(). If you
are transferring data to the property sheet’s member variables, you must do it
before you make the call to DoModal(). If the property sheet is dismissed with
the OK button, DoModal() will return IDOK. Otherwise, it will return IDCANCEL—just
like a modal dialog box does. If you are transferring data from the property
sheet’s member variables, you must do it before the end of the function in which
you called the property sheet.
|