Click here to Skip to main content
11,713,864 members (85,059 online)
Click here to Skip to main content

SAPrefs - Netscape-like Preferences Dialog

, 20 Apr 2002 CPOL 366.5K 2.8K 121
Rate this:
Please Sign up or sign in to vote.
A base class for a prefereneces dialog, similar to that used in Netscape

Sample Image

CSAPrefsDialog is a base for a preferences dialog, similar to the one used in Netscape. Page selection is handled with a CTreeCtrl - pages can be "sub-pages" of other pages!

Use is very similar to CPropertySheet / CPropertyPage : create a CSAPrefsDialog object. This implements the container for your property pages. The pages are objects of type CPrefsSubDlg (a subclass of CDialog). Using these classes is as easy as this :

// our preferences dialog
CSAPrefsDialog dlg;

// the "pages" (all derived from CSAPrefsSubDlg)
CPage1 page1;
CPage2 page2;
CPage3 page3;
CPage4 page4;

// add 3 pages
dlg.AddPage(page1, "Page 1");
dlg.AddPage(page2, "Page 2");
dlg.AddPage(page3, "Page 3");

// this one will be a child node on the tree 
// (&page3 specifies the parent)
dlg.AddPage(dlg4, "Page 4", &page3);

// the prefs dialog title
dlg.SetTitle("This is pretty");

// text drawn on the right side of the shaded
// page label. this does not change when the
// pages change, hence "constant".
dlg.SetConstantText("SAPrefs");

// launch it like any other dialog...
dlg1.m_csText = m_csStupidCString;
if (dlg.DoModal()==IDOK)
{
  m_csStupidCString = dlg1.m_csText;
}

To use this in your own application, you need to follow these steps :

  1. Add the following files to your project :
    • CSAPrefsDialog.cpp,.h
    • CSAPrefsSubDlg.cpp,.h
    • CSAPrefsStatic.cpp,.h
  2. Copy the IDD_SAPREFS dialog resource from the sample project to your project.
  3. Create your preference "pages" in the resource editor with the following settings :
    • Style - Child
    • Border - None
    • No OK or Cancel buttons! (pretend these are CPropertyPages!)
  4. Use Class Wizard to create the dialog classes for the pages.
  5. In the .cpp and .h files for your new dialog classes, replace all occurances of CDialog with CSAPrefsSubDlg. (you will need to #include "SAPrefsSubDlg.h")
  6. Follow the steps shown in the sample code (above) to create the main dialog and add your pages.

Notes

  • The parent/child relationships that you specify with AddPage(page, text, &parent) are strictly cosmetic. Only the tree control knows about them! As far as the CSAPrefsDialog is concerned, all pages are equal and independent of each other.
  • OnOK and OnCancel are virtual functions of CSAPrefsSubDlg. You can override them in your own derived dialogs. But, you will have to do this by-hand (implement them like any other function). Class Wizard will not be able to do this for you. These functions are called, for every page that has been viewed, when CSAPrefsSubDlg is closed by OK or Cancel.
  • You should handle "Help" as with CPropertyPage : with a WM_NOTIFY message handler :
    BOOL CMyPage::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
    {
    	NMHDR* pnmh = (LPNMHDR) lParam;
    	if (pnmh->code == PSN_HELP) {
    		AfxGetApp()->WinHelp(some help ID);
    	}
    
    	return CSAPrefsSubDlg::OnNotify(wParam, lParam, pResult);
    }
  • Your pages should fit inside the IDC_DLG_FRAME rectangle on the IDD_SAPREFS dialog. CSAPrefsSubDlg does not resize to fit your pages, like CPropertySheet does. This keeps things nice and simple. Auto-resizing would be a nice addition, but I don't need it for my purposes, so I didn't add it.

History

  • Jan 27 2002 - updated source files.
  • 21 April 2002 - updated source files.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Chris Losinger
Software Developer
United States United States
Chris Losinger is the president of Smaller Animals Software, Inc..

You may also be interested in...

Comments and Discussions

 
QuestionThanks ! Good code, one question though Pin
VijayDighe26-Apr-12 11:49
memberVijayDighe26-Apr-12 11:49 
AnswerRe: Thanks ! Good code, one question though Pin
Chris Losinger26-Apr-12 16:25
memberChris Losinger26-Apr-12 16:25 
QuestionBug? Pin
Manfred Drasch1-Oct-06 23:29
memberManfred Drasch1-Oct-06 23:29 
AnswerRe: Bug? Pin
Chris Losinger2-Oct-06 1:54
memberChris Losinger2-Oct-06 1:54 
QuestionHow to use SAPrefs as a tab control item? Pin
samluo357-Aug-06 18:57
membersamluo357-Aug-06 18:57 
AnswerRe: How to use SAPrefs as a tab control item? Pin
Chris Losinger8-Aug-06 1:04
memberChris Losinger8-Aug-06 1:04 
QuestionPossible to dynamically add and delete pages? Pin
helsten226-Mar-06 3:44
memberhelsten226-Mar-06 3:44 
QuestionHow 2 use button for change the pages !!! Pin
c++ noob22-Dec-05 6:35
memberc++ noob22-Dec-05 6:35 
GeneralAdded some functionality Pin
John Simmons / outlaw programmer5-Apr-05 6:31
memberJohn Simmons / outlaw programmer5-Apr-05 6:31 
QuestionHow do you copy a dialog resource? Pin
jhorstkamp27-Oct-03 9:36
memberjhorstkamp27-Oct-03 9:36 
AnswerRe: How do you copy a dialog resource? Pin
Chris Losinger27-Oct-03 9:41
memberChris Losinger27-Oct-03 9:41 
QuestionSet selected page on left? Pin
The Lady of Shallots16-Oct-03 10:20
memberThe Lady of Shallots16-Oct-03 10:20 
GeneralSAPrefs a the basis for an app... Pin
Docta G15-Sep-03 18:02
memberDocta G15-Sep-03 18:02 
GeneralRe: SAPrefs a the basis for an app... Pin
Chris Losinger16-Sep-03 1:23
memberChris Losinger16-Sep-03 1:23 
GeneralRe: SAPrefs a the basis for an app... Pin
Docta G16-Sep-03 18:53
memberDocta G16-Sep-03 18:53 
GeneralRe: SAPrefs a the basis for an app... Pin
Chris Losinger17-Sep-03 1:31
memberChris Losinger17-Sep-03 1:31 
QuestionHow can I make the subpages appear extended? Pin
DanYELL1-May-03 17:32
memberDanYELL1-May-03 17:32 
AnswerRe: How can I make the subpages appear extended? Pin
Chris Losinger2-May-03 1:32
memberChris Losinger2-May-03 1:32 
GeneralAnother Idea for Netscape-like Preferences Dialog Pin
Koundinya2-Mar-03 22:53
memberKoundinya2-Mar-03 22:53 
GeneralRe: Another Idea for Netscape-like Preferences Dialog Pin
Chris Losinger3-Mar-03 3:35
memberChris Losinger3-Mar-03 3:35 
GeneralDestroyWindow Pin
Anonymous13-Jan-03 9:39
sussAnonymous13-Jan-03 9:39 
GeneralRe: DestroyWindow Pin
Chris Losinger13-Jan-03 9:50
memberChris Losinger13-Jan-03 9:50 
GeneralProblem selecting controls on the pages Pin
GNW6-Dec-02 10:56
sussGNW6-Dec-02 10:56 
GeneralRe: Problem selecting controls on the pages Pin
Chris Losinger6-Dec-02 11:00
memberChris Losinger6-Dec-02 11:00 
GeneralRe: Problem selecting controls on the pages Pin
Anonymous13-Dec-02 10:42
sussAnonymous13-Dec-02 10:42 
GeneralWinHelp Pin
iyiac22-Nov-02 16:14
memberiyiac22-Nov-02 16:14 
GeneralRe: WinHelp Pin
Chris Losinger22-Nov-02 18:13
memberChris Losinger22-Nov-02 18:13 
GeneralQuestion Pin
Anonymous20-Nov-02 7:39
sussAnonymous20-Nov-02 7:39 
GeneralRe: Question Pin
Chris Losinger20-Nov-02 8:24
memberChris Losinger20-Nov-02 8:24 
GeneralRe: Question Pin
Anonymous20-Nov-02 11:03
sussAnonymous20-Nov-02 11:03 
GeneralExporting values Pin
ArielR12-Nov-02 5:59
memberArielR12-Nov-02 5:59 
GeneralRe: Exporting values Pin
Chris Losinger12-Nov-02 6:07
memberChris Losinger12-Nov-02 6:07 
GeneralRe: Exporting values Pin
ArielR12-Nov-02 10:14
memberArielR12-Nov-02 10:14 
GeneralRe: Exporting values Pin
Chris Losinger13-Nov-02 5:06
memberChris Losinger13-Nov-02 5:06 
GeneralRe: Exporting values Pin
ArielR13-Nov-02 7:01
memberArielR13-Nov-02 7:01 
GeneralRe: Exporting values Pin
Chris Losinger13-Nov-02 7:08
memberChris Losinger13-Nov-02 7:08 
GeneralRe: Exporting values Pin
ArielR15-Nov-02 23:27
memberArielR15-Nov-02 23:27 
GeneralStart page Pin
PascalG17-Sep-02 21:02
sussPascalG17-Sep-02 21:02 
GeneralRe: Start page Pin
Chris Losinger18-Sep-02 3:47
memberChris Losinger18-Sep-02 3:47 
GeneralRe: Start page Pin
PascalG23-Sep-02 20:02
memberPascalG23-Sep-02 20:02 
GeneralRe: Start page : Solved ? Pin
PascalG24-Sep-02 21:02
memberPascalG24-Sep-02 21:02 
Generala much needed feature. Pin
kokie29-Aug-02 12:26
memberkokie29-Aug-02 12:26 
GeneralRe: a much needed feature. Pin
Chris Losinger29-Aug-02 13:37
memberChris Losinger29-Aug-02 13:37 
GeneralRe: a much needed feature. Pin
kokie30-Aug-02 10:26
memberkokie30-Aug-02 10:26 
Generalthank you so much!!! Pin
hiddukel22-Jul-02 2:19
susshiddukel22-Jul-02 2:19 
QuestionHow to tell when a page gains focus? Pin
dazinith19-Jul-02 4:16
memberdazinith19-Jul-02 4:16 
AnswerRe: How to tell when a page gains focus? Pin
Chris Losinger19-Jul-02 4:29
memberChris Losinger19-Jul-02 4:29 
GeneralRe: How to tell when a page gains focus? Pin
dazinith19-Jul-02 4:32
memberdazinith19-Jul-02 4:32 
GeneralReally Good Stuff Pin
JohnJ24-Apr-02 22:53
memberJohnJ24-Apr-02 22:53 
GeneralUnicode and CPropertyPage Pin
Chris Ling22-Apr-02 23:20
memberChris Ling22-Apr-02 23:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 21 Apr 2002
Article Copyright 1999 by Chris Losinger
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid