Click here to Skip to main content
6,931,354 members and growing! (19,506 online)
Email Password   helpLost your password?
 
Desktop Development » Tabs & Property Pages » General     Intermediate License: The Code Project Open License (CPOL)

SAPrefs - Netscape-like Preferences Dialog

By Chris Losinger

A base class for a prefereneces dialog, similar to that used in Netscape
VC6, MFC, Dev
Posted:18 Nov 1999
Updated:20 Apr 2002
Views:233,779
Bookmarked:90 times
printPrint Friendly   add Share
      Discuss Discuss   Broken Article?Report  
141 votes for this article.
Popularity: 9.67 Rating: 4.50 out of 5

1

2
2 votes, 10.0%
3

4
18 votes, 90.0%
5

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)

About the Author

Chris Losinger


Member
Chris Losinger is the president of Smaller Animals Software, Inc..
Occupation: Software Developer
Location: United States United States

Other popular Tabs & Property Pages articles:

 
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 137 (Total in Forum: 137) (Refresh)FirstPrevNext
GeneralBug? PinmemberManfred Drasch0:29 2 Oct '06  
GeneralRe: Bug? PinsupporterChris Losinger2:54 2 Oct '06  
GeneralHow to use SAPrefs as a tab control item? Pinmembersamluo3519:57 7 Aug '06  
GeneralRe: How to use SAPrefs as a tab control item? PinsupporterChris Losinger2:04 8 Aug '06  
GeneralPossible to dynamically add and delete pages? Pinmemberhelsten24:44 26 Mar '06  
GeneralHow 2 use button for change the pages !!! Pinmemberc++ noob7:35 22 Dec '05  
GeneralAdded some functionality PinmemberJohn Simmons / outlaw programmer7:31 5 Apr '05  
GeneralHow do you copy a dialog resource? Pinmemberjhorstkamp10:36 27 Oct '03  
GeneralRe: How do you copy a dialog resource? PinsupporterChris Losinger10:41 27 Oct '03  
GeneralSet selected page on left? PinmemberThe Lady of Shallots11:20 16 Oct '03  
GeneralSAPrefs a the basis for an app... PinmemberDocta G19:02 15 Sep '03  
GeneralRe: SAPrefs a the basis for an app... PinsupporterChris Losinger2:23 16 Sep '03  
GeneralRe: SAPrefs a the basis for an app... PinmemberDocta G19:53 16 Sep '03  
GeneralRe: SAPrefs a the basis for an app... PinsupporterChris Losinger2:31 17 Sep '03  
GeneralHow can I make the subpages appear extended? PinmemberDanYELL18:32 1 May '03  
GeneralRe: How can I make the subpages appear extended? PinsupporterChris Losinger2:32 2 May '03  
GeneralAnother Idea for Netscape-like Preferences Dialog PinmemberKoundinya23:53 2 Mar '03  
GeneralRe: Another Idea for Netscape-like Preferences Dialog PinsupporterChris Losinger4:35 3 Mar '03  
GeneralDestroyWindow PinsussAnonymous10:39 13 Jan '03  
GeneralRe: DestroyWindow PinsupporterChris Losinger10:50 13 Jan '03  
GeneralProblem selecting controls on the pages PinsussGNW11:56 6 Dec '02  
GeneralRe: Problem selecting controls on the pages PinsupporterChris Losinger12:00 6 Dec '02  
GeneralRe: Problem selecting controls on the pages PinsussAnonymous11:42 13 Dec '02  
GeneralWinHelp Pinmemberiyiac17:14 22 Nov '02  
GeneralRe: WinHelp PinsupporterChris Losinger19:13 22 Nov '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 20 Apr 2002
Editor: Chris Maunder
Copyright 1999 by Chris Losinger
Everything else Copyright © CodeProject, 1999-2010
Web17 | Advertise on the Code Project