| Tenouk C & C++ | MFC Home | Another ATL Tutorial 1 | ATL Attributes 1 | Download | Site Index |


 

 

 

 

Another ATL Tutorial Using Visual C++ .NET part 2

 

 

 

 

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.

  • Generating the Type Library.

  • Implementing the Connection Point Interfaces.

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;

 

MFC C++ code snippet - ATL Tutorial Using Visual C++ .NET

 

Listing 11.

 

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

 

  1. In Class View, expand Polygon and PolygonLib to display _IPolyCtlEvents.
  2. Right-click _IPolyCtlEvents. On the shortcut menu, click Add, and then click Add Method.

 

Figure 20: Adding methods to Polygon.

 

Figure 20: Adding methods to Polygon.

 

  1. Select a Return Type of void.
  2. Enter ClickIn in the Method name box.
  3. Under Parameter attributes, select the in box.
  4. Select a Parameter type of LONG.
  5. Type x as the Parameter name, and click Add.

 

Figure 21: Adding ClickIn method through Add Method Wizard.

 

Figure 21: Adding ClickIn method through Add Method Wizard.

 

  1. Next, repeat step 5 to 8, select the in box, enter a Parameter type LONG and Parameter name of y, and click the Add button.
  2. Click Finish.
  3. Repeat the steps above to define a ClickOut method with the same LONG parameters x and y, the same Parameter attributes and the same void return type.

 

Figure 22: Adding ClickOut 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:

dispinterface _IPolyCtlEvents

{

   properties:

   methods:

   [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);

};