Click here to Skip to main content
13,594,792 members
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 5 Apr 2001

Subclassing Dialogs and Property Pages

, 5 Apr 2001
Rate this:
Please Sign up or sign in to vote.
You have a lot of dialogs that have a lot of properties in common. You'd like to derive the specialized ones from the general ones. Here's how.


One of the limits of the ClassWizard is its inability to handle various useful forms of subclassing. In particular, it does not intrinsically allow you to subclass from a subclass, or specify a subclassed subclass as a variable. For example, I have a class called CSmartDropdown which does dynamic resizing of combo boxes. I have a subclass CIDCombo which is a subclass of CSmartDropdown which handles the issues of combo box initialization in a better fashion than the resources.

The two classes CIDCombo and CSmartDropdown were merged in the CIDCombo class I publish on my Web site.

In fact, I often work with a CGraphicsCombo class which is a subclass of CIDCombo, but supports owner-draw bitmap images, or CColorCombo which is a subclass of CGraphicsCombo that displays some selected colors. So I often work several levels of derivation down, and the ClassWizard makes this inconvenient.

But if you want to subclass a dialog or property page, it gets even worse. Consider the case where you have a combo box which appears on every property page, or on every dialog, and a few buttons that have the same behavior. It seems silly to create a set of independent dialogs that handle this, yet there is no support in ClassWizard that helps you.

Fortunately, it is not hard to change this. You just have to know the Magic Incantations. Here they be!

First, create a dialog with the common controls that are shared by all the subclasses you plan to create. This dialog will not actually be used (although it could be, I'm not that ambitious here...), but it is used to create all the handlers. You will find in the .h file a declaration of the constructor:

CMyDialog(CWnd * parent = NULL);

Change this to read

CMyDialog(CWnd * parent = NULL) { ASSERT(FALSE); } // never create!

Add a new constructor:

CMyDialog(CWnd * parent = NULL) { ASSERT(FALSE); } // never create!

Go into the .cpp file and modify the constructor code. It reads

CMyDialog::CMyDialog(CWnd * parent /* = NULL */)
        : CDialog(CMyDialog::IDD, parent)

Change this to read

CMyDialog::CMyDialog(UINT id, CWnd * parent /* = NULL */)
        : CDialog(id, parent)

Now when you create a new dialog which is a subclass, just create the dialog as you normally would. Now comes the tedious part that ClassWizard should have done for you (send email to the Microsoft Wish site if you think ClassWizard should support this!)

Go into the .h file for your new class and change all instances of CDialog to CMyDialog

Go into the .cpp file for your new class and change all instances of CDialog to CMyDialog

That's it. You're done. When you create a subclassed dialog, you still have to copy the common controls from your master dialog template into the child dialogs (note that Microsoft could have made this easy, by simply inheriting the controls during dialog construction; a subclassed dialog would open the resource of each enclosing parent and include all the controls from that class into the current dialog, which is fairly trivial to implement). 

You can do exactly the same technique to subclass a CPropertyPage-derived class.

The views expressed in these essays are those of the author, and in no way represent, nor are they endorsed by, Microsoft.

Send mail to with questions or comments about this article.
Copyright © 1999 All Rights Reserved


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Joseph M. Newcomer
United States United States
PhD, Computer Science, Carnegie Mellon University, 1975
Certificate in Forensic Science and the Law, Duquesne University, 2008

Co-Author, [i]Win32 Programming[/i]

You may also be interested in...

Comments and Discussions

GeneralHi to all !! Pin
vidya.p.nair30-Jul-07 23:01
membervidya.p.nair30-Jul-07 23:01 
GeneralRe: Hi to all !! Pin
Joseph M. Newcomer31-Jul-07 13:09
memberJoseph M. Newcomer31-Jul-07 13:09 
GeneralThanks Pin
sfdougl13-Jun-05 6:17
membersfdougl13-Jun-05 6:17 
QuestionHow about CFormViews? Pin
infidel7924-Jul-03 5:19
memberinfidel7924-Jul-03 5:19 
Questionhow add icon to the tab in the property page Pin
siong22-Jul-03 17:27
membersiong22-Jul-03 17:27 
AnswerRe: how add icon to the tab in the property page Pin
Joseph M. Newcomer26-Jul-03 7:29
memberJoseph M. Newcomer26-Jul-03 7:29 
QuestionHow to use the Wizard Dialog in VC? Pin
wangnanjing21-May-03 20:08
memberwangnanjing21-May-03 20:08 
AnswerRe: How to use the Wizard Dialog in VC? Pin
Joseph M. Newcomer22-May-03 4:03
memberJoseph M. Newcomer22-May-03 4:03 
GeneralProperty pages in VC++ Pin
sheethal10-Jun-02 1:51
membersheethal10-Jun-02 1:51 
GeneralRe: Property pages in VC++ Pin
*RPM16-Apr-03 3:23
member*RPM16-Apr-03 3:23 
GeneralProblem with Proprerty pages Pin
Anonymous14-Mar-02 18:50
memberAnonymous14-Mar-02 18:50 
GeneralRe: Problem with Proprerty pages Pin
Joseph M. Newcomer14-Mar-02 19:45
memberJoseph M. Newcomer14-Mar-02 19:45 
GeneralMistake in header Pin
dramon5-Apr-01 22:02
memberdramon5-Apr-01 22:02 
GeneralRe: Mistake in header Pin
Sean Cundiff9-Apr-01 7:41
memberSean Cundiff9-Apr-01 7:41 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.180621.3 | Last Updated 6 Apr 2001
Article Copyright 2001 by Joseph M. Newcomer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid