This documentation is archived and is not being maintained.

Step 4: Adding the Client Object

Visual Studio .NET 2003

In this step, you will add a client object (named CDispCtl) to the client project. This client object will be implemented by a simple, lightweight control added by the Add Class dialog box.

Adding the client object to the project

  1. In Class View, right-click the DispClient project.
  2. On the shortcut menu, click Add and then click Add Class.

    The Add Class dialog box appears.

  3. From the ATL folder, double-click ATL Control.

    The ATL Control Wizard appears.

  4. In the Short name field, type DispCtl. The remaining fields are automatically completed.
  5. Click the Options tab.
  6. Select Minimal control.
  7. Change the Threading Model to Single.
  8. Click the Interfaces tab.
  9. Move IDataObject and IProvideClassInfo2 to the Supported column.
  10. Click Finish to generate the CDispCtl class.

CDispCtl inherits from all the ATL template classes required for a light control. Additionally, the class inherits from IDataObjectImp, providing methods to support Uniform Data Transfer, and IProvideClassInfo2Impl, allowing the access of type information for the object's coclass from other COM objects.

Registration of the control is achieved using the registration_script attribute. The parameter on this attribute is the name of the registration script, in this case Control.rgs, which is the default registration script for controls.

Also included is a default implementation of the OnDraw method.

The final step is to add the event_receiver attribute to the new class.

Adding an attribute to an existing class

  1. In Class View, double-click the DispClient node and click the CDispCtl class.

    This will display the class definition for CDispCtl.

  2. Just above the class definition is the attribute block for the class. Add event_receiver(com) to the attribute block.

The resulting attribute list should resemble the following:


In the next step, you will add the needed interfaces to the control object.

On to Step 5 | Back to Step 3

See Also

Attributes Tutorial | ATL Article Overview | ATL Class Overview