![[Sample page 1 - 30K]](/KB/dialog/ezoptionsdlg/EZOptionsDlg1.gif)
![[Sample page 2 - 30K]](/KB/dialog/ezoptionsdlg/EZOptionsDlg2.gif)
Introduction
The point behind this article is to build a base for building a Netscape Prefs like dialog without compromising on the benefits provided by CPropertySheet and CPropertyPage.
To implement this dialog:
Step 1
Add the files present in the source zip file above, to your project.
Add the following lines in some globally available file like stdafx.h:
#include "EZPropertyPage.h"
#include "EZOptionsDlg.h"
Step 2
Add a dialog to your application and add a class for it, say CPrefDlg. Replace every occurrence of CDialog with CEZOptionsDlg in the header file and the source file of the dialog. This dialog takes the place of a property sheet.
Step 3
Edit the dialog template and add a tree control somewhere on the dialog.
Add the following lines to the OnInitDialog handler to introduce your tree control to the parent class CEZOptionsDlg:
SetTreeCtrl(IDC_OPT_TREE);
Step 4
Add a property page, CPage1 say, to your application and replace every instance of CPropertyPage with CEZPropertyPage in the header and source files.
Now, as you would do in a regular property sheet, declare a member variable for CPage1 in the dialog class (CPrefDlg) created in step 2. Add the following code similar to that of the normal CPropertySheet::AddPage. But CPage1::Create should be called before calling AddPage.
m_page1.Create(IDD_PROPPAGE_PAGE1);
AddPage(&m_page1,_T("Page1"));
If you want to add a page as a child item, add the title of the parent item as the third parameter. To avoid unexpected behavior, the titles should be unique.
Here is the OnInitDialog function:
#include "EZOptionsDlg.h"
class CPage1;
class CPrefDlg:public CEZOptionsDlg
{
...
private:
CPage1 m_page1;
};
BOOL CPrefDlg::OnInitDialog()
{
...
SetTreeCtrl(IDC_OPT_TREE);
...
m_page1.Create(IDD_PROPPAGE_PAGE1);
AddPage(&m_page1,_T("Page1"));
SelectPage(_T("Page1"));
m_wndTree.ExpandAll();
}
Again, to remove a page, the title is to be used. This is the reason why I say the titles should be unique.
RemovePage(_T("Page1"));
Repeat the above step to add more pages.
The demo project should do the rest of the explanation.