Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows


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. Its 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.

Practical Learning: Creating a Property Sheet



  1. In the Class View, right-click Geometry and click either New Class or Add -> Add
    Class...

  2. If you are using MSVC 6, set the Class Type to MFC Class
    If you are using MSVC 7, click MFC Class and click Open
    Set the name of the class to CGeomeSheet

  3. In the Base Class combo box, select CPropertySheet

Free download pdf