ClassWizard: Adding Automation Properties and Methods
This article explains how to use ClassWizard to add Automation (formerly OLE Automation) and to an Automation class. Topics include:
Adding a property to your automation class
Adding a method to your automation class
A class that supports Automation exposes a set of functions (known as methods) and properties — the dispatch interface — for use by other applications. ClassWizard offers a simple, quick way to implement this ability in your classes.
Adding a Property to Your Automation Class
To add a member variable property to your Automation class
Use member variable properties if you need to allocate storage for the values. The most common case for member variables is when there is no user interface to be updated when changes occur.
In ClassWizard, click the Automation tab.
Select a class name that supports Automation. (Your document class supports Automation if you checked the Automation check box in AppWizard when creating your project.) Notice that the Add Property and Add Method buttons are unavailable for classes that do not support Automation.
Click Add Property and supply the following information:
External Name: Name that automation clients use to refer to this property.
Type: Any of the choices found in the list box.
Implementation: Click Member Variable.
Variable Name: Name of the C++ class data member.
Tip You can also supply the name of a notification function that is called when the variable changes.
Click OK to close ClassWizard.
To add a Get/Set method property to your Automation class
Use Get/Set methods properties if you are dealing with calculated properties. The most common use of Get/Set properties is to reflect changes in a user interface for calculated properties or items that are updated.
In ClassWizard, click the Automation tab.
Select a class name that supports Automation. You can also select the name of your document class if you checked the Automation check box in AppWizard when creating your project. Notice that the Add Property and Add Method buttons are unavailable for classes that do not support Automation.
Click Add Property and supply the following information:
External Name: Name that automation clients use to refer to this property.
Type: Any of the choices found in the list box.
Implementation: Choose Get/Set Methods.
Get Function: The name of the member function used to get the property value.
Set Function: The name of the member function used to set the property value. This function can include special processing for when the property value is changed.
Add any method parameters you need, using the grid control:
Double-click in the first empty row under the Name label to activate an edit control; then enter the parameter name.
Double-click the row under the Type label to activate a drop-down list; then select the parameter's type.
Continue this procedure until you have entered all the parameters you need. To delete a parameter, delete its row by clicking once in the row and pressing the DELETE key or the BACKSPACE key.
Click OK to create the necessary code.
Tip To create a read-only property, delete the name of the Set Function.
Adding a Method to Your Automation Class
In ClassWizard, click the Automation tab.
Select a class name that supports Automation. You can also select the name of your document class if you checked the Automation check box in AppWizard when creating your project. Notice that the Add Property and Add Method buttons are unavailable for classes that do not support Automation.
Open the Add Method dialog box and supply the following information:
External Name: Name that automation clients use to refer to this method.
Internal Name: Name of the C++ member function to add to the class.
Return Type: Any choice found in the list box.
Add any method parameters you need, using the grid control:
Double-click in the first empty row under the Name label to activate an edit control; then enter the parameter name.
Double-click the row under the Type label to activate a drop-down list; then select the parameter's type.
Continue this procedure until you have entered all the parameters you need. To delete a parameter, delete its row by clicking once in the row and pressing the DELETE key or the BACKSPACE key.
Click OK in the Add Method dialog box to create the member function.
See Also ClassWizard: Accessing Automation Servers, Automation Topics