Property Sheet Inside Property Page
Posted
by Victor M. Grinenko
on December 11th, 1999

Environment: VC6
You can use embedded property sheet in your application. I use "Creating a Property Sheet Inside a Dialog" by Zafir Anjum, as start solution.
1st step.
You must derive class from CPropertyPage and add CPropertySheet member to this class:
class CPropertyPageWithPropertySheet : public CPropertyPage
{
...
public:
virtual BOOL UpdateData(BOOL bSaveAndValidate);
virtual void AddPage(CPropertyPage *pPage);
...
...
// Implementation
protected:
CPropertySheet m_internal_sheet;
// Generated message map functions
//{{AFX_MSG(CPropertyPageWithPropertySheet)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
...
};
2nd step.
Override OnInitDialog() for configure property page and start it Create() method:
BOOL CPropertyPageWithPropertySheet::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
m_internal_sheet.EnableStackedTabs( FALSE );
m_internal_sheet.Create(this, WS_CHILD | WS_VISIBLE , 0);
m_internal_sheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT);
m_internal_sheet.ModifyStyle( 0, WS_TABSTOP );
// move to left upper corner
m_internal_sheet.SetWindowPos( NULL, 0, 0, 0, 0,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
3rd step.
After this you can add property pages to CPropertySheet member. For this I use AddPage() function:
void CPropertyPageWithPropertySheet::AddPage(CPropertyPage *pPage)
{
m_internal_sheet.AddPage(pPage);
}
4th step.
For data exchange and validation you must override UpdateData() function in your dialog class and derived CPropertyPage class:
BOOL CPropertyPageWithPropertySheet::UpdateData(BOOL bSaveAndValidate)
{
if(!CPropertyPage::UpdateData(bSaveAndValidate))
return FALSE;
// check property sheet. Need when OK button pressed in main dialog
return m_internal_sheet.GetActivePage()->UpdateData(bSaveAndValidate);
}
... and add change to DoDataExchange():
void CPropertyPageWithPropertySheet::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPropertyPageWithPropertySheet)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
// this need for check data when user change tab in parent property sheet
if(m_internal_sheet)
if(!m_internal_sheet.GetActivePage()->UpdateData(pDX->m_bSaveAndValidate))
pDX->Fail();
}
This code responds for validation, when user changes tabs in parent property sheet.
5th step.
Also you must add calls m_page_with_sheetXX.UpdateData( ) in parent dialog overrided UpdateData() function:
BOOL CPs_in_psDlg::UpdateData(BOOL bSaveAndValidate)
{
if(!CDialog::UpdateData(bSaveAndValidate))
return FALSE;
// check addition property sheet in property pages
if(m_page_with_sheet0)
if(!m_page_with_sheet0.UpdateData(bSaveAndValidate))
return FALSE;
if(m_page_with_sheet1)
if(!m_page_with_sheet1.UpdateData(bSaveAndValidate))
return FALSE;
// check main property sheet. Need when OK button pressed in main dialog
return m_sheet.GetActivePage()->UpdateData(bSaveAndValidate);
}

Comments
Good job...! Thanks!!
Posted by Legacy on 09/02/2003 12:00amOriginally posted by: Pentomic
It's Very what I searching.......!
ReplyThanks for.....your job.
Thanks! It works great!
Posted by Legacy on 08/27/2003 12:00amOriginally posted by: Kostya
I'm using this class in my program and it works very good.
ReplyGreat !!!!!!!!
Posted by Legacy on 01/23/2003 12:00amOriginally posted by: Meena
Thank you for you demo code...It got me out of the stupid mistake i had made
ReplyProblem: Does not work with a RichEdit control !!!!
Posted by Legacy on 10/26/2002 12:00amOriginally posted by: Bundy
i made a dialog based application with the property sheet model you have presented,
and if i add a RichEdit control to ANY of the pages, then the page simply disappears
when i click on its tab! (instead of being displayed, it disappears, the page AND the tab).
i have also tried this with your own sample project, and i got the same results.
personally, i couldn't figure out how to fix this. i *think* the problem
is with the UpdateData function, but i'm not sure.
Reply
What to do when using CMyPropertySheet instead of CPropertySheet?
Posted by Legacy on 05/22/2002 12:00amOriginally posted by: Simon De meulemeester
Hello,
I've tried your code and it works fine. However, when I try to use my own defined property sheet the compiler says that no default constructor is available for m_internal_sheet. Do you or anybody else knows how to solve this problem?
ReplyHow can I use a CPropertyPage as a CDialog ??? thanks
Posted by Legacy on 04/28/2002 12:00amOriginally posted by: juhasaproblem
I've made a CPropertyPage that I use in a CPropertySheet but I'd like to use too this CPropertyPage as a CDialog : the problem is that I can't close this CPropertyPage...
ReplyThanks for help me !!!!
Problem with CFormView
Posted by Legacy on 03/05/2002 12:00amOriginally posted by: Ofer Erlich
ReplyVery Cool
Posted by Legacy on 07/06/2001 12:00amOriginally posted by: Keivan Eshghi
I implemented your code in my project. It works fine.
Thanks
ReplyCan't Get it work under SDI environment
Posted by Legacy on 01/06/2001 12:00amOriginally posted by: Victor
as above...any suggestions??
ReplySetting the focus in inside property page
Posted by Legacy on 12/30/1999 12:00amOriginally posted by: Joe Ersinghaus
ReplyLoading, Please Wait ...