Using ClassWizard

ClassWizard (choose ClassWizard on the View menu) works like a programming assistant: it makes it easier for you to do routine tasks such as creating new classes, adding message handlers, overriding MFC virtual functions, and gathering data from controls in a dialog box, form view, or record view.

ClassWizard works only with applications that use MFC classes, unlike ClassView, which works with MFC, ATL, or generic (user-defined) classes. ClassView does not recognize classes unless they are registered in the ClassWizard database (.vcc) file.

With ClassWizard, you can:

  • Create new classes derived from many of the main framework base classes that handle Windows messages and recordsets.
  • Map messages to functions associated with windows, dialog boxes, controls, menu items, and accelerators.
  • Create new message-handling member functions.
  • Delete message-handling member functions.
  • See which messages have message handlers already defined and jump to the handler program code.
  • Define member variables that initialize, gather, and validate data entered into dialog boxes or form views.
  • Add Automation methods and properties when creating a new class.
  • Work with Existing Classes and Type Libraries.

Adding a Function with ClassWizard

ClassWizard lets you create handler functions and connect them to the menu items, toolbar buttons, and accelerators whose commands they respond to.

  • To connect a dialog box or other user-interface object to a menu command or toolbar button with ClassWizard, you must first create the dialog box, menu entry, or toolbar button and its object ID using the appropriate eMbedded Visual C++ resource editor.

  • You can bind more than one user-interface object to a single function. You can bind both a menu command and a toolbar button to a single function, for instance. In this case, selecting either object in your application causes the same action.

  • To add a function and edit its related code, you should make your selections in this order on the ClassWizard Message Maps tab:

    1. Under Project, select the project that contains the class to edit.
    2. Under Class name, select the class.
    3. Under Object IDs, select an object ID.
    4. Under Messages, select a Message.
    5. Under Member functions, you can select an associated function to edit or delete, you can choose Add Function to add a member function to the class.

    By convention, the names of all message-handling functions begin with the prefix On.

  • Override virtual functions in much the same way, also on the Message Maps tab:

    1. Select a Class name.
    2. Under Object IDs, select the class name again.
    3. Under Messages, select a virtual function to override.
    4. Choose Add Function.

Adding a Variable with ClassWizard

ClassWizard lets you add member variables to some classes. For example, you can add member variables to a dialog class to represent the dialog box controls. Use the following tips:

  • Edit Variables is available in the ClassWizard dialog box only for classes with a data map. This includes dialog, form view, and record view classes. Neither ClassWizard nor AppWizard make changes to your code outside the data map.
  • By convention, the names of all member variables begin with the prefix m_.
  • By using ClassWizard to map a dialog control to a dialog-class member variable with the Value property (the default), you can use dialog data exchange and dialog data validation. This eliminates the need to manually move data between the control and the member variable. It also allows you to specify validation rules for the data.
  • You can also map a dialog control to a dialog-class member variable with the Control property. This creates a member variable of an appropriate class, such as CEdit. You can then call the member functions of the control object through this variable.

Adding Code with ClassWizard

After you add a new member function in the ClassWizard dialog box, select the function under Member functions on the Message Maps tab, and then choose Edit Code to add the implementation code for the function. This opens an eMbedded Visual C++ source code editor window with the file containing the class for the member function. A highlighted comment indicates where to add your code.

Using ClassWizard Tab Dialogs

The following table describes each ClassWizard tab.

Tab Purpose
Message Maps Browse the messages that a class can handle or create; edit or delete the member functions mapped to the messages. Use the Edit Code button to open the source code editor and jump to the code for a message handler function.
Member Variables Bind member variables to dialog, form view, or record view controls. You can also bind record view member variables both to record view controls and to the columns of a table in your data source.
Automation Create and edit the Automation capabilities of your application. For example, you can create Automation properties and methods.
ActiveX Events Specify actions that cause your ActiveX control to fire events. For example, you can specify that a mouse click on your control fires a particular event that the container for a control container responds to with a handler. This tab is for ActiveX control developers. If you are using an ActiveX control in your dialog box and want to handle events, use the Message Maps tab just as you would for handling messages.
Class Info Browse and set general class options. You can set a message filter for a class message to determine what messages ClassWizard offers to map to handlers in your class.