How To Derive From Classes not Listed in ClassWizard

Article translations Article translations
Article ID: 99161 - View products that this article applies to.
This article was previously published under Q99161
Expand all | Collapse all

SUMMARY

Microsoft ClassWizard supports deriving classes only from the classes listed in the Class Type field of the Add Class dialog box. To create a class derived from a previously derived class or to derive from another class based on the Microsoft Foundation Class Library CWnd class that is not listed in the Class Type field, a few extra steps are required. The text below presents these steps.

MORE INFORMATION

For example, suppose the following derivation tree is desired:
   MyDerivedClass
         ^
         |
     MyBaseClass
         ^
         |
      CDialog
				
or, it is desirable to derive a class from a class based on CWnd that is not listed in the Class Type field in the Add Class dialog box, such as CFileDialog. There is no predefined method to create this type of class hierarchy using the ClassWizard. However, by using the parsing techniques ClassWizard uses, you can create these class hierarchies.

The steps below use CDialog as the default class type. Before proceeding, determine which predefined class type is closest to the desired base class. For example, CFileDialog is similar to CDialog. If none of the classes correspond closely to your desired class, use the generic CWnd class.

To create a class with multiple levels of derivation, perform the following three steps:

  1. Use ClassWizard to create MyDerivedClass, deriving it from CDialog (or another appropriate predefined class).
  2. Use ClassWizard to create MyBaseClass, deriving it from CDialog (or another appropriate predefined class).
  3. Edit the code generated for MyDerivedClass and replace all references to CDialog with MyBaseClass. This step is very important; many errors occur if this is not done correctly and these errors may be difficult to track down.
To create a class based on a class based on CWnd that is not supported by ClassWizard, perform the following two steps:

  1. Use ClassWizard to create MyDerivedClass, deriving it from CDialog (or another appropriate predefined class based on CWnd).
  2. Edit the code generated for MyDerivedClass and replace all references to CDialog with the name of the class from which you are deriving this class, for example, CFileDialog. This step is very important; many errors occur if this is not done correctly and these errors may be difficult to track down.
Then, for either type of class, perform the following three steps:

  1. Delete the project .CLW file.
  2. Start App Studio, load your project .RC file, and activate Class Wizard.
  3. Because the project does not have a .CLW file, ClassWizard prompts to generate a .CLW file. Choose Yes to generate the file. NOTE: You must generate this file in App Studio. If you attempt to generate the file in Visual Workbench, VWB instructs you to generate the file in App Studio.
Once App Studio has created the .CLW file, the base class of the derived class has been changed successfully. To verify this, view the class in ClassWizard and see the data in the Class Info dialog box.

For classes created using multiple levels of derivation, you can use ClassWizard to pass system messages, such as WM_INITDIALOG, to the base class as well. To do this, perform the following nine steps:

  1. Start ClassWizard.
  2. Select the MyDerivedClass class.
  3. Select MyDerivedClass in the Object IDs window.
  4. Select the WM_INITDIALOG message in the Messages window.
  5. Choose Add Function to add a function skeleton that calls the OnInitDialog() function in MyBaseClass.
  6. Select the MyBaseClass class.
  7. Select MyBaseClass in the Object IDs window.
  8. Select the WM_INITDIALOG message in the Messages window.
  9. Choose Add Function to add a function skeleton that calls the OnInitDialog() function in CDialog. This step is required only once. If you derive additional classes from the base class, you do not need to redo this operation.

Properties

Article ID: 99161 - Last Review: July 1, 2004 - Revision: 3.1
APPLIES TO
  • The ClassWizard, when used with:
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 1.5 Professional Edition
    • Microsoft Visual C++ 1.51
    • Microsoft Visual C++ 1.52 Professional Edition
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 2.0 Professional Edition
    • Microsoft Visual C++ 2.1
    • Microsoft Visual C++ 2.2
    • Microsoft Visual C++ 4.0 Standard Edition
    • Microsoft Visual C++ 4.1 Subscription
    • Microsoft Visual C++ 4.2 Professional Edition
    • Microsoft Visual C++ 5.0 Standard Edition
    • Microsoft Visual C++ 6.0 Service Pack 5
Keywords: 
kbhowto kbwizard KB99161
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com