Click here to Skip to main content
12,695,739 members (31,797 online)
Rate this:
Please Sign up or sign in to vote.
See more: VS2008 Visual-Studio MFC , +
I have a dialog box.
I want to add property sheet to that dialog box(not modeless).
Please help me!
Posted 17-Dec-12 22:29pm
Jochen Arndt 18-Dec-12 5:47am
A CPropertySheet already provides you with a dialog style window with embedded pages. Because it behaves like dialogs (calling DoModal() after creation), it can't be simply added to a dialog.

You usually use CPropertySheet windows instead of a dialog. If you want a dialog with a common area and embedded tabs, you must create it yourself. Optionally use a CPropertySheet derived class or extend your dialog class to embed CPropertyPages.
Member 7909353 18-Dec-12 6:13am
Actually I want to add system menu in CPropertySheet
Richard MacCutchan 18-Dec-12 7:27am
A dialog has a system menu by default. If you want to add your own menu items then you can add them to the system menu, or include your own menu resource in your dialog.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Property sheet provides a very nice user interface, it allows several dialog templates to be integrated
together, and the user can switch among them by using tab control. This is especially useful if there are
many common controls that need to be included in a single dialog template.
Because property sheet is very similar to dialog box, we can create a dialog box then change it to
property sheet. The reason for creating property sheet this way is because currently Developer Studio does
not support direct implementation of property sheet.
In MFC, there are two classes that should be used to implement property sheet: CPropertySheet and
CPropertyPage. The former class is used to create a frame window that contains tab control, the second
class is used to implement each single page.
To implement a property sheet, we first need to derive a class from CPropertySheet, then declare one
or more CPropertyPage type member variables within it. Each variable will be associated with a dialog
template. Because CPropertyPage is derived from class CDialog, all the public and protected members of
CDialog are accessible in the member functions of CPropertyPage.

Sample 6.1-1\DB demonstrates how to create application based on property sheet. First it is generated
as a dialog based application by using Application Wizard (the default classes are CDBApp and CDBDlg), then
the base class of CDBDlg is changed from CDialog to CPropertySheet. Since class CPropertySheet does
not have member IDD to store the dialog template ID, we need to delete the following line from class
Chapter 6. Dialog Box
enum { IDD = IDD_DIALOG_DB };
The default dialog box template IDD_DIALOG_DB will not be used, so it is also deleted from the
application resources. The following is the modified class:
class CDBDlg : public CPropertySheet
CDBDlg(CWnd* pParent = NULL);
virtual void DoDataExchange(CDataExchange* pDX);
HICON m_hIcon;
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
We also need to find all the keyword CDialog in the implementation file of CDBDlg and change them to
CPropertySheet. The changes should happen in the following functions: the constructor of CDBDlg,
function DoDataExchange(…), OnInitDialog(), OnSysCommand(…), OnPaint(…), and message mapping
Next we need to create each single page. The procedure of creating a property page is the same with
creating a dialog box, except that when adding new class for a dialog box template, we must derive it from
class CPropertyPage. In the sample, three dialog templates are added to the application, their IDs are
ID_DIALOG_PAGE1, ID_DIALOG_PAGE2 and ID_DIALOG_PAGE3 respectively. Three classes CPage1, CPage2 and
CPage3 are also added through using Class Wizard, which are all derived from CPropertyPage. When
doing this, we need to provide the ID of the corresponding dialog template.
In class CDBDlg, a new member variable is declared for each page:
#include "Page.h"
class CDBDlg : public CPropertySheet
CPage1 m_page1;
CPage2 m_page2;
CPage3 m_page3;
The pages should be added in the constructor of CPropertySheet by calling function
CPropertySheet::AddPage(…). The following is how each page is added in the sample:
CDBDlg::CDBDlg(CWnd* pParent /*=NULL*/) : CPropertySheet()
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
Function CPropertySheet::AddPage(…) has only one parameter, it is a pointer to CPropertyPage type
These are the necessary steps for implementing property sheet. For each property page, we can also
add message handlers for the controls, the procedure of which is the same with that of a standalone dialog
By default, the property sheet will be implemented in “tab” mode: there will be a tab control in the
property sheet, which can be used to select property pages. The property sheet can also be implemented in
“wizard” mode, in which case tab control will be replaced by two buttons (labeled with “Previous” and
“Next”). In this mode, the pages can only be selected sequentially through button clickings.
To enable wizard mode, all we need to do is calling function CPropertySheet::
SetWizardMode()after all the pages have been added. For example, if we want to enable wizard mode in
the sample, we should implement the constructor of CDBDlg as follows:
CDBDlg::CDBDlg(CWnd* pParent /*=NULL*/) : CPropertySheet()
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
Sample 6.2-2\DB is the same with sample 6.2-1\DB, except that the property sheet is implemented in
wizard mode.
If we need to implement a property sheet dialog box in an SDI or MDI application, most of the steps
are still the same. We can start by creating a new CPropertySheet based class, then adding dialog
templates and CPropertyPage based classes, using them to declare new variables in CPropertySheet
derived class, calling function CPropertySheet::AddPage(…) in its constructor. We can call function
CPropertySheet::DoModal() at anytime to invoke the property sheet.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100