Adding an MFC Class

HomeOverviewHow Do ITutorial

To add classes derived from MFC (Microsoft Foundation Class Library) classes to your project, you can use any of the following tools: ClassView, WizardBar, ClassWizard, or the New Class command on the Insert menu. You simply specify the new class's name, select the base class from which it is to be derived, and select the ID of the dialog box with which it is to be associated (if any). WizardBar creates a header file and an implementation file for the new class.

Note   You can add MFC classes to an ATL COM application if you initially created the application with MFC support.

To add an MFC class to your project

  1. Open the New Class dialog box as described in the New Class dialog box.

  2. In the Class type drop-down list, select MFC Class.

  3. In the Name box, specify the name of the new class.

    The name you specify is reflected in the read-only File name box, where the .cpp file is specified. By default, the header file and the implementation file have the same name as the class file.

  4. Choose a base class from which to derive the new class. There are two kinds of MFC classes:
  5. For dialog-based classes, select the resource with which the class is to be associated from the Dialog ID drop-down list.

  6. Select the type of Automation support: None, Automation, or Createable by type ID. (Note that the base class must support Automation in order for any Automation options to be available.)

    Note   Use ClassWizard's Automation tab to add Automation methods and properties to an existing class. These methods and properties define a dispatch interface that Automation clients can use.

  7. Click OK to create the new class and add it to the project.

    The new class immediately appears in ClassView, and you can view its header and implementation files in the FileView pane of the project workspace.

See Also   Adding an ATL Class, Adding a Generic Class