Click here to Skip to main content
11,647,748 members (70,369 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VS2008 MFC VC++
I have a dialog box. I want to add property sheet to that dialog box(not modeless). Please help me!
Posted 17-Dec-12 21:29pm
Jochen Arndt at 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 at 18-Dec-12 6:13am
Actually I want to add system menu in CPropertySheet
Richard MacCutchan at 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 CDBDlg: Chapter 6. Dialog Box 144 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 { public: CDBDlg(CWnd* pParent = NULL); //{{AFX_DATA(CDBDlg) //}}AFX_DATA //{{AFX_VIRTUAL(CDBDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); //}}AFX_VIRTUAL protected: HICON m_hIcon; //{{AFX_MSG(CDBDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; 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 macros. 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 { …… protected: …… 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() { //{{AFX_DATA_INIT(CDBDlg) //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); AddPage(&m_page1); AddPage(&m_page2); AddPage(&m_page3); } Function CPropertySheet::AddPage(…) has only one parameter, it is a pointer to CPropertyPage type object. 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 box. 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() { //{{AFX_DATA_INIT(CDBDlg) //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); AddPage(&m_page1); AddPage(&m_page2); AddPage(&m_page3); SetWizardMode(); } 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
0 500
1 F-ES Sitecore 410
2 OriginalGriff 322
3 DamithSL 315
4 CPallini 250
0 OriginalGriff 1,342
1 994
2 DamithSL 971
3 Sergey Alexandrovich Kryukov 873
4 CPallini 795

Advertise | Privacy | Mobile
Web03 | 2.8.150804.3 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2015
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