Program examples compiled using Visual Studio/C++ .Net 2003 compiler on Windows XP Pro machine with Service Pack 2. Topics and sub topics for this tutorial are listed below. Don’t forget to read Tenouk’s small disclaimer. The supplementary note for this tutorial is the .NET early stage development.
Step 5: Adding an Event
In this step, you will add a ClickIn and a ClickOut event to your ATL control. You will fire the ClickIn event if the user clicks within the polygon and fire ClickOut if the user clicks outside. The tasks to add an event are as follows:
Adding the ClickIn and ClickOut Methods
When you created the ATL control in step 2, you selected the Connection points check box. This created the _IPolyCtlEvents interface in the Polygon.idl file. Note that the interface name starts with an underscore. This is a convention to indicate that the interface is an internal interface. Thus, programs that allow you to browse COM objects can choose not to display the interface to the user. Also note that selecting Connection points added the following line in the Polygon.idl file to indicate that _IPolyCtlEvents is the default source interface:
[default, source] dispinterface _IPolyCtlEvents;
The source attribute indicates that the control is the source of the notifications, so it will call this interface on the container.
Now add the ClickIn and ClickOut methods to the _IPolyCtlEvents interface.
To add the ClickIn and ClickOut methods
Figure 20: Adding methods to Polygon.
Figure 21: Adding ClickIn method through Add Method Wizard.
Figure 22: Adding ClickOut method through Add Method Wizard.
Check the Polygon.idl file to see that the code was added to the _IPolyCtlEvents dispinterface. The _IPolyCtlEvents dispinterface in your Polygon.idl file should now look like this:
[id(1), helpstring("method ClickIn")] void ClickIn([in]LONG x, [in] LONG y);
[id(2), helpstring("method ClickOut")] void ClickOut([in] LONG x, [in] LONG y);