PropertyPage

Property page is a small dialog window usually displays data fields of some category of an object.

Property Sheet

Property Sheet is the top window which holdes a collection of property pages. property pages generally comes as category with some heading and appears as tabs in property sheet dialog.

Example

An easy example of property sheet dialog is the property dialog of drives in windows explorer. The steps to see this dialog is to "right" click on any drive and click on "Properties" in the context menu. A dialog like below image will open. This is the property sheet dialog box. It contains several property pages and "General" page is the default selected page.

property sheet and page for c drive

Design

Design of property sheet and property page are simple. A property page is like a normal dialog and derived from the class CPropertyPage. It has its own messsage handing part to manage its own events.

A Property sheet is also a general dialog box derived from CPropertySheet class. CPropertySheet class has AddPage() function to add individual pages to the propery sheet. Property sheet can implement its own events for buttons and controls. Very common buttons which are included in the main sheet is "OK", "Cancel", "Apply" etc. Property sheet always have a default selected property page in it. This page index can be passed in constructor. Default index is zero.

This example is with the help of C++ wrapped classes. CPropertyPage and CPropertySheet actually wraps some basic data structure in it. In the next section we will see these data structures.

PropertySheet VC++ Project

A VC++ project should have two types of dialog resources. One main dialog for property sheet display and other are a series of property page dialog resources for each property page. These resources can be added to the project using "Insert -> Resource" menu option in VC++.

add new property page dialog resource

There are three dialogs one main property sheet and two property pages dialog resource in our project. Resources looks -

property sheet demo dialog resource

Project should include an Application class, PropSheet dialog class and series of property page classes.

Source code

class PropertyPage1 : public CPropertyPage
{
  DECLARE_DYNAMIC(PropertyPage1)

public :
  PropertyPag1();
  virtual ~PropertyPage1();

  enum { IDD = IDD_PROPPAGE_SMALL1 };

protected :
  virtual void DoDataExchange(CDataExchange* pDX);

  DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNAMIC(PropertyPage1, CPropertyPage)

PropertyPage1::PropertyPage1()
  : CPropertyPage(IDD_PROPPAGE_SMALL1)
{}

PropertyPage1::~PropertyPage1()
{}

void PropertyPage1::DoDataExchange(CDataExchange* pDX)
{
  CPropertyPage::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(PropertyPage1, CPropertyPage)
END_MESSAGE_MAP()

class PropertyPage2 : public CPropertyPage
{
  DECLARE_DYNAMIC(PropertyPage1)

public :
  PropertyPage2();
  virtual ~PropertyPage2();
  enum { IDD = IDD_PROPPAGE_SMALL2 };

protected:
  virtual void DoDataExchange(CDataExchange* pDX);
  DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNAMIC(PropertyPage1, CPropertyPage)

PropertyPage2::PropertyPage2()
  : CPropertyPage(IDD_PROPPAGE_SMALL2)
{}

PropertyPage2::~PropertyPage1()
{}

void PropertyPage2::DoDataExchange(CDataExchange* pDX)
{
  CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(PropertyPage2, CPropertyPage)
END_MESSAGE_MAP()

/* CPropertySheetDemoDlg dialog */
class CPropertySheetDemoDlg : public CDialogEx
{
public :
  CPropertySheetDemoDlg(CWnd* pParent = NULL);
  enum { IDD = IDD_PROPERTYSHEETDEMO_DIALOG };

protected :
  virtual void DoDataExchange(CDataExchange* pDX);

protected :
  HICON m_hIcon;

  virtual BOOL OnInitDialog();
  afx_msg void OnPaint();
  afx_msg HCURSOR OnQueryDragIcon();
  DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNAMIC(PropertySheetDlg, CPropertySheet)

BEGIN_MESSAGE_MAP(PropertySheetDlg, CPropertySheet)
END_MESSAGE_MAP()

BOOL CPropertySheetDemoApp::InitInstance()
{
  PropertySheetDlg PropSheetDlg(L"Property Sheet Demo");
  PropertyPage1 page1;
  PropertyPage2 page2;
  PropSheetDlg.AddPage(&page1);
  PropSheetDlg.AddPage(&page2);
  m_pMainWnd = &PropSheetDlg;
  PropSheetDlg.DoModal();
  return FALSE;
}

Output

property page sheet demo application

About our authors: Team EQA

Further readings

Where is WinMain() function in MFC application ?

MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.

What is the utility of CWinApp class?

This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...

Basic steps in Win32 GUI Application with source code.

Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.

What is a Window CallBack procedure and what is its utility?

DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.

What are LPARAM and WPARAM in window proc function?

LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.

What are the basic steps of a typical MFC based application?

We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...

#