EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of VC++/WIN32/MFC Questions #Next question

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 };
10 
11  protected :
12    virtual void DoDataExchange(CDataExchange* pDX);
13 
14    DECLARE_MESSAGE_MAP()
15  };
16  IMPLEMENT_DYNAMIC(PropertyPage1, CPropertyPage)
17 
18  PropertyPage1::PropertyPage1()
19    : CPropertyPage(IDD_PROPPAGE_SMALL1)
20  {}
21 
22  PropertyPage1::~PropertyPage1()
23  {}
24 
25  void PropertyPage1::DoDataExchange(CDataExchange* pDX)
26  {
27    CPropertyPage::DoDataExchange(pDX);
28  }
29 
30  BEGIN_MESSAGE_MAP(PropertyPage1, CPropertyPage)
31  END_MESSAGE_MAP()
32 
33  class PropertyPage2 : public CPropertyPage
34  {
35    DECLARE_DYNAMIC(PropertyPage1)
36 
37  public :
38    PropertyPage2();
39    virtual ~PropertyPage2();
40    enum { IDD = IDD_PROPPAGE_SMALL2 };
41 
42  protected:
43    virtual void DoDataExchange(CDataExchange* pDX);
44    DECLARE_MESSAGE_MAP()
45  };
46  IMPLEMENT_DYNAMIC(PropertyPage1, CPropertyPage)
47 
48  PropertyPage2::PropertyPage2()
49    : CPropertyPage(IDD_PROPPAGE_SMALL2)
50  {}
51 
52  PropertyPage2::~PropertyPage1()
53  {}
54 
55  void PropertyPage2::DoDataExchange(CDataExchange* pDX)
56  {
57    CPropertyPage::DoDataExchange(pDX);
58  }
59  BEGIN_MESSAGE_MAP(PropertyPage2, CPropertyPage)
60  END_MESSAGE_MAP()
61 
62  /* CPropertySheetDemoDlg dialog */
63  class CPropertySheetDemoDlg : public CDialogEx
64  {
65  public :
66    CPropertySheetDemoDlg(CWnd* pParent = NULL);
67    enum { IDD = IDD_PROPERTYSHEETDEMO_DIALOG };
68 
69  protected :
70    virtual void DoDataExchange(CDataExchange* pDX);
71 
72  protected :
73    HICON m_hIcon;
74 
75    virtual BOOL OnInitDialog();
76    afx_msg void OnPaint();
77    afx_msg HCURSOR OnQueryDragIcon();
78    DECLARE_MESSAGE_MAP()
79  };
80  IMPLEMENT_DYNAMIC(PropertySheetDlg, CPropertySheet)
81 
82  BEGIN_MESSAGE_MAP(PropertySheetDlg, CPropertySheet)
83  END_MESSAGE_MAP()
84 
85  BOOL CPropertySheetDemoApp::InitInstance()
86  {
87    PropertySheetDlg PropSheetDlg(L"Property Sheet Demo");
88    PropertyPage1 page1;
89    PropertyPage2 page2;
90    PropSheetDlg.AddPage(&page1);
91    PropSheetDlg.AddPage(&page2);
92    m_pMainWnd = &PropSheetDlg;
93    PropSheetDlg.DoModal();
94    return FALSE;
95  }

Output

property page sheet demo application

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Sat 26 Apr/2014 23:15:44(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.