|
To implement its functionality, the property pages are put together and kept as an entity by an object called a property
sheet that acts as their parent. Like other controls, we will see that the property pages must be added to a property sheet.
There is no resource to create for a property sheet. A property sheet is based on the
CPropertySheet class, which is not based on CDialog but it provides the same functionality as
a dialog. Therefore, a property sheet is sometimes called, or referred to as, a dialog box. Instead,
CPropertySheet is based on the CWnd class. Therefore, to implement your property
page(s), you can simply declare a CPropertySheet variable and use it to display the application or you can programmatically derive a class from
CPropertySheet. The CPropertySheet class is declared in the afxdlgs.h header file.
If you decide to directly use the CPropertySheet class, declare a variable for it where the application will need to be displayed or instantiated, which could be in the
CWinApp::InitInstance() event. To display the property sheet, call its DoModal() method. This could be done as follows:
BOOL CMyApp::InitInstance()
{
CPropertySheet MySheet;
MySheet.DoModal();
}
To specify your property pages as belonging to the property page, declare a variable for each one of them. Then, call the
CPropertySheet::AddPage() method to add each property page. The syntax of this method is:
void AddPage(CPropertyPage *pPage);
This method takes the variable of each page and adds it as part of the property sheet. Here is an example:
BOOL CmyApp::InitInstance()
{
CPropertySheet MySheet;
CFirstPage First;
CSecondPage Second;
MySheet.AddPage(&First);
MySheet.AddPage(&Second);
MySheet.DoModal();
}
If you want to have better access to the property sheet as a class, you should derive your own class from
CPropertySheet. You will have the ability to use any or a combination of these constructors:
CPropertySheet();
CPropertySheet(UINT nIDCaption, CWnd *pParentWnd=NULL, UINT iSelectPage=0);
CPropertySheet(LPCTSTR pszCaption, CWnd *pParentWnd=NULL, UINT iSelectPage=0);
The default constructor is used in the same circumstance as the
CPropertySheet variable declared above. It allows you to create a CPropertySheet instance and change its characteristics later. Both the second and the third constructors allow you to specify a caption for the property. If you want to use the first, create a string with an identifier in a String Table and use that ID as the argument. Otherwise, when declaring a variable using the second constructor, you can directly provide a null-terminated string as argument.
If you want to specify a title for the property sheet, you can call the
CPropertySheet::SetTitle() method. Its syntax is:
void SetTitle(LPCTSTR lpszText, UINT nStyle = 0);
The first argument is a null terminated string that will be the new title. If you want the caption to display the string starting with “Properties for”, pass a second argument as
PSH_PROPTITLE.
|