This article extends Chris Losinger's work on CSAPrefsDlg.
CSettingsDialog
is an MFC class which enables to customize the project settings. The settings of a project are categorized as pages based on their nature of those pages. If you are familiar with the Netscape preferences-dialog, you will have no problem understanding the interfaces of CSettingsDialog
Unlike those similar dialogs posted in CodeProject and CodeGuru, which only allow one type of Window (e.g.,CPropertyPage
or CDialog), CSettingsDialog
allows any CWnd
derived windows to be used as setting pages (Look at the demo figures above, a property page, a form view and a generic CWnd
Windows are used for different settings.I believe that this design extend the applicability of the class to meet the need of various situations. Furthermore, each tree node does not have to have a setting page to be associated, it can be a generic tree node, e.g., a label used as a category index.
New features are added to this newest version. CHtmlView
is supported (take a look at the first demo picture). However, in order to use the CHtmlView
(or derived) class, you need to override the OnMouseActive
virtual function to avoid the ASSERT
ion error in your CHtmlView
(or derived) class. Another new feature of CSettingsDialog
is that it support both modal and modaless state of display. There are some rules need to be followed. For the modeless dialog, the dialog variable must be declared as a pointer and be instantiated using new
operator. You need to create the dialog using member function CSettingsDialog::Create()
and using ShowWindow(SW_SHOW)
to diaplay the dialog. The Apply button in the dialog is disabled in the modal state and is enabled in the modeless state.
CSettingsDialog
IDD_SETTINGS_DLG
dialog resource from the sample project to your project. OK
or Cancel
buttons! CSettingsDialog
as demonstrated in the demo project: CSettingsDialog dlg; CSettingsDialog dlg; dlg.AddPage(RUNTIME_CLASS(CMyHtmlView), _T("Project Setting"), 0); CPropPage1 *pModelPage = (CPropPage1*) dlg.AddPage(RUNTIME_CLASS(CPropPage1), _T("Model"), IDD_PROPERTY_PAGE1, _T("Project Setting")); dlg.AddPage(RUNTIME_CLASS(CPropPage2), _T("Visibility"), IDD_PROPERTY_PAGE2, pModelPage); dlg.AddPage(RUNTIME_CLASS(CMyFormView), _T("Form View"), IDD_FORMVIEW, pModelPage); dlg.AddPage(RUNTIME_CLASS(CMyView), _T("Generic View Page"), 0); dlg.AddPage(NULL, _T("Generic Tree Item"), 0); dlg.SetTitle("Project Settings"); dlg.SetLogoText("CSettingsDialog 1.0"); int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel }
CSettingsDialog
variable as a pointer in your parent window class, eg.,m_pDlg
in CMainFrame
. CSettingsDialog
: CSettingsDialog *m_pDlg = new CSettingsDialog(this) ;
if (!m_pDlg) { m_pDlg = new CSettingsDialog(this); m_pDlg->AddPage(RUNTIME_CLASS(CMyHtmlView), _T("Project Setting"), 0); CPropPage1 *pModelPage = (CPropPage1*) m_pDlg->AddPage(RUNTIME_CLASS(CPropPage1), _T("Model (PropertyPage)"), IDD_PROPERTY_PAGE1, _T("Project Setting")); m_pDlg->AddPage(RUNTIME_CLASS(CPropPage2), _T("Visibility (PropertyPage)"), IDD_PROPERTY_PAGE2, pModelPage); m_pDlg->AddPage(RUNTIME_CLASS(CMyFormView), _T("Form View"), IDD_FORMVIEW, pModelPage); m_pDlg->AddPage(RUNTIME_CLASS(CMyView), _T("Generic View Page"), 0); m_pDlg->AddPage(NULL, _T("Generic Tree Item"), 0); m_pDlg->SetTitle("Project Settings"); m_pDlg->SetLogoText("CSettingsDialog 1.0"); m_pDlg->Create(); } m_pDlg->ShowWindow(SW_SHOW);
CSettingsDialog
in your parent window which "owns" the dialog.