To add an object to an ATL project, you use the ATL Object Wizard. Click New ATL Object on the Insert menu, and the ATL Object Wizard appears.
In the first ATL Object Wizard dialog box, select the category of object you want to add to your current ATL project. Some of the options you can select are a basic COM object, a control tailored to work in Internet Explorer, and a property page. In this tutorial, you will create a standard control, so set the category as Controls on the left, then on the right select Full Control. Finally, click Next.
A set of property pages is displayed that allows you to configure the control you are inserting into your project. Type "PolyCtl" as the short name. The other fields are automatically completed.
The Class field shows the C++ class name created to implement the control. The .H File and .CPP File fields show the files created to contain the definition of the C++ class. The CoClass is the name of the component class for this control, and Interface is the name of the interface on which your control will implement its custom methods and properties. The Type is a description for the control, and the ProgID is the readable name that can be used to look up the CLSID of the control.
Now enable support for rich error information and connection points for your control:
You will color in the polygon when you draw it, so add a Fill Color stock property:
You are finished selecting options for your control. Click OK.
When you created your control, several code changes and additions were made. The following files were created:
File | Description |
PolyCtl.h | Contains most of the implementation of the C++ class CPolyCtl. |
PolyCtl.cpp | Contains the remaining parts of CPolyCtl. |
PolyCtl.rgs | A text file that contains the registry script used to register the control. |
PolyCtl.htm | An HTML file that contains the source of a Web page that contains a reference to the newly created control, so that you can try it out in Internet Explorer immediately. |
The Wizard also performed the following code changes:
The file PolyCtl.h is the most interesting because it contains the main code that implements your control.
You are now ready to build your control:
Next, you will add a custom property to the control.