ClassWizard: Tips and Troubleshooting
Home | Overview | How Do I | Tutorial
This article summarizes key tips and troubleshooting advice for using ClassWizard effectively. The following topics are covered:
Using ClassWizard Tab Dialogs
ClassWizard has a "tab dialog" user interface: the ClassWizard dialog box contains "tabs" that resemble the tabs on a group of file folders. Each tab's label shows what kind of functionality you can edit on that tab. To select a tab, click its label. Use the following tips:
- Use the Message Maps tab to browse the messages that a class can handle or to create, edit, or delete the member functions mapped to the messages. Use the Edit Code button to jump to a message handler function's code in the Visual C++ source code editor.
- Use the Member Variables tab to 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.
- Use the Automation tab to create and edit the Automation capabilities of your application. For example, you can create Automation properties and methods.
- Use the ActiveX Events tab to specify actions that will 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 control's container responds to with a handler. Note that 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.
- Use the Class Info tab to browse and set general class options. You can set a class's message filter to determine what messages ClassWizard offers to map to handlers in your class. You can also view or set a "foreign object" associated with your dialog form view or record view class. For information about foreign objects, see the article ClassWizard: Foreign Objects.
Adding Functions with ClassWizard
ClassWizard lets you create handler functions and connect them to the menu items, toolbar buttons, and accelerators whose commands they respond to. Use the following tips:
- 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 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:
- Select the Project that contains the class you want to edit.
- Select a Class name.
- Select an Object ID.
- Select a Message.
You can then select an associated function to edit or delete, or click the Add Function button 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:
- Select a Class name.
- In the Object IDs box, select the class name again.
- In the Messages box, select a virtual function to override.
- Click Add Function.
Adding Variables 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's 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 (DDX) and dialog data validation (DDV). This eliminates the need to move data between the control and the member variable yourself. It also allows you to specify validation rules for the data. For more information about DDX and DDV, see Dialog Data Exchange and Dialog Data Exchange and Validation.
- 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 from ClassWizard
After you've added a new member function in the ClassWizard dialog box, click Edit Code to add the implementation code for the function. A Visual C++ source code editor window opens with the file containing the class for the member function. A highlighted comment indicates where to add your code. Use the following tip:
- You can select a function in ClassWizard's Message Maps tab and then click Edit Code to locate and examine code quickly.
Opening Your
RC File
Visual C++ lets you open resources in two ways. You can open individual resources (in compiled form) in the Visual C++ resource editors. Or you can open the .rc file to edit it directly as a text file. Use the following tip:
- To open the .rc file as text, click the Open command on the File menu and change the Open As option to Text.