|


Introduction
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
ASSERTion 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. How to use CSettingsDialog Use of the class is pretty simple. Just follow the following steps:
-
Add the following files to your project :
- SettingsDialog.cpp, SettingsDialog.h
- CSAPrefsStatic.cpp,.h
- Copy the
IDD_SETTINGS_DLG dialog resource from the sample project to your project.
-
Create your Settings "pages" in the resource editor. If the page is a dialog, make
sure that the dialog has the following settings:
- Style - Child
- Border - None
- No
OK or Cancel buttons!
Use Class Wizard to create the dialog classes for the pages.
- If used as a modal dialog:
Create and initialize the
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)
{
}
else if (nResponse == IDCANCEL)
{
}
- If used as a modaless dialog:
- Declare a
CSettingsDialog variable as a pointer in your parent window class,
eg.,m_pDlg in CMainFrame.
- Instantiate an object of
CSettingsDialog:
CSettingsDialog *m_pDlg = new CSettingsDialog(this) ;
- create, initialize, and display the settings pages and dialog, e.g.,
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);
-
Add a message handler of
CSettingsDialog in your parent window which "owns" the dialog.
-
Finally do not forget to free the dialog memory in the parent window's destructor.
-
If you are not sure exactly how to do it, take a look at the attached demo project,
Acknowledgments
History
- V1.0 02/12/02 First version of the class
- V1.1 03/01/02
- Memory leak bug fixed.
- Thick frame style of CView type class (including CFormView) is removed to make it look more industrial standard.
- Html view supported.
- V1.2 03/08/02 Both modal and modaless states supported. The demo project shows the CSettingsDialog in both modal and modaless way.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 55 (Total in Forum: 55) (Refresh) | FirstPrevNext |
|
 |
|
|
 |
|
|
 |
|
|
In this code, it supports to attach any CWnd on CSettingsDialog. But I need to attach CFormView on MDI child Frame. Please help me.
Nhiem
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Hi!
How to access variable members of the pages after the user clicks OK?
It seems that when the user clicks OK, all the pages are destroyed, so the following code crashes:
CSettingsDialog dlg; int nRet;
dlg.AddPage(NULL, _T("General"), 0); CMyPage1* pPage1=(CMyPage1*) dlg.AddPage(RUNTIME_CLASS(CMyPage1), _T("Page 1"), IDD_MYPAGE1, _T("Page 1"); nRet = dlg.DoModal();
if (nRet==IDOK) { AfxMessageBox pPage1->MyVar); }
Does anyone can help me?
Thks in advance! Appstmd http://www.appstmd.com
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi Appstmd,
I have the same problem. You are right! After you klick OK Button all pages are destroyed!!! I don't know why the author of this bad class don't answer your question. I think you must go into the code solve this problem yourself.
Because this behavior the class isn't usable. In other respects is a nice work.
Regards,
Axel
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi! Yes, indeed you must go into the code and make sure that after clicking OK or Cancel the pages won't be destroyed. This behaviour should be added in the destructor of the class, not when you hit OK or Cancel. Best regards, Christian.
I am in love with VC++
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
There are a a lot of memory leaks - it looks like the dialogs are not being deleted properly. I am using multiple instances of the same dialog, and using dialogs instead of property pages - does this affect it?
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
the following code dose work in my project,please try it
BOOL CSettingsDialog::DestroyPages() { for (int i=0; i<m_pInfo.GetSize(); i++) { PAGE_INFO *pInfo = (PAGE_INFO *)m_pInfo.GetAt(i); if (pInfo && pInfo->pWnd) { if (::IsWindow(pInfo->pWnd->m_hWnd)) { pInfo->pWnd->DestroyWindow(); if (!(pInfo->bViewClass)) { delete(pInfo->pWnd); pInfo->pWnd=NULL; }
} else { delete(pInfo->pWnd); pInfo->pWnd=NULL; } } delete pInfo;//delete pInfo=NULL; }
m_pInfo.RemoveAll(); return(true); }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi everybody, here is a small fix to be sure that once the parent dialog is create, the DDX mecanism and standard behavior of CPropertyPage and CPropertyPageEx is called
void CSettingsDialog::ShowPage(const PAGE_INFO *pInfo, UINT nShow /* = SW_SHOW */)
.............
if( pInfo->pWnd->IsKindOf( RUNTIME_CLASS(CView) ) ) ((CView*)pInfo->pWnd)->OnInitialUpdate(); else { ((CPropertyPageEx*)pInfo->pWnd)->OnSetActive(); } } same when closing
Programming is not an end in itself but only a means to an end
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I saw on the homepage that there is a version 1.3. But the links on the homepage don't work. Does anyone have the code for 1.3??
Maybe someone could email it to me?
Thanks
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
As the links for new versions are broken, I used current version posted in this page. I have detected that memory leaks are generated because of some problems freeing memory.
To avoid it, this is the code for DestroyPages() method:
BOOL CSettingsDialog::DestroyPages() { for (int i=0; i { PAGE_INFO *pInfo = (PAGE_INFO *)m_pInfo.GetAt(i); if (pInfo && pInfo->pWnd) { if (::IsWindow(pInfo->pWnd->m_hWnd)) pInfo->pWnd->DestroyWindow(); // Destroy the windows if (!(pInfo->bViewClass)) { delete(pInfo->pWnd); // Delete the C++ object pInfo->pWnd = NULL; } } }
return(true); }
And when the window is modeless, you have to override DestroyWindow with this code in it:
BOOL CSettingsDialog::DestroyWindow() { DestroyPages(); return CDialog::DestroyWindow(); }
Hope this helps Regards, Jaime
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
|
I checked your website and these links are broken:
http://yellowine.netfirms.com/SettingsDlg/SettingsDlg_src.zip http://yellowine.netfirms.com/SettingsDlg/SettingsDlg_demo.zip
The files on codeproject seem to be v1.0
Please let me know. Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Seems there is even a v1.3, but the website is pretty f***ed up: links and forum do not work.
Please, upload the new version.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Hi ! I tried to use CSettingsDlg class with Property Pages. It is displaying properly. But the problem is: the controls on dialog are not listening. For example, On a dialog box, I have an Edit box and Radio Button. On cliking Apply button, UpdateData method of the dialog is not being called. In the same way, I am not able to catch the event BN_CLICKED in case of Radio Button. In other words, I don't have any control over Controls.
Can anybody throw light over it. Thanks,
Amit Manocha
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
I have used the class CHtmlView to make a web browser but when I run applet that use javax.swing, my web browser doesn't work, it doens't accept swing... How to make my web browser accept swing ?
Thx a lot,
Sky
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
For goodness sake, it seems you've done a good job here, but then blown it by failing to post your updates to this site. The zip files on your free-hosted site do not download reliably, so we can't get at the corrected version of your software.
I know its good fun having your own little website, but you're using codeproject.com to get exposure for your coding effort, why not use it to distribute the software?
Yours,
An annoyed user who will now use someone else's options dialog for his super high profile commercial application that would have had your name in its credits!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Have you got version 1.3? I was not able to download it. Obviously in 1.3 there are some memory problems fixed... I have a version of SettingsDlg.cpp/SettingsDlg.h with creation date 03/07/02 and i'm getting some memory leaks.  If you have got a newer version please mail it to me.
thanks in advance...
Michael
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
 | why |  | jiva | 16:09 23 Mar '02 |
|
|
first,I must thank you for your program. but,I cant not use it in Winxp(memory leak),In olevar1.h, while (pidlWalker->mkid.cb). and ,1.2 ver,I can not visit your homepage .
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|