Adding the ClickOut Event

When the user clicks the left mouse button and the insertion point is outside the control circle, the ClickOut event should fire. The ClickOut event is simpler than the ClickIn event in that it defines no arguments.

To add the ClickOut event

  1. On the View menu, click ClassWizard.

  2. Click the ActiveX Events tab.

  3. From the Class name drop-down list box, select CCircCtrl.

  4. Click Add Event.

    The Add Event dialog box appears.

  5. In the edit control of the External name drop-down combo box, type ClickOut.

  6. Click OK to close the Add Event dialog box.

    This returns you to the ActiveX Events tab. Notice that the implementation of the ClickOut event appears as:

    Implementation:
    void FireClickOut();
    
  7. Click OK to confirm your choices and close ClassWizard.

As with the ClickIn event, ClassWizard creates the code to add the ClickOut event, modifying the files CIRC.ODL, CIRCCTL.H, and CIRCCTL.CPP.

ClassWizard modifies the CCircCtrl class’s event map in CIRCCTL.CPP to add a macro entry for the ClickOut event:

BEGIN_EVENT_MAP(CCircCtrl, COleControl)
    //{{AFX_EVENT_MAP(CCircCtrl)
    EVENT_CUSTOM("ClickIn", FireClickIn, VTS_XPOS_PIXELS  VTS_YPOS_PIXELS)
    EVENT_CUSTOM("ClickOut", FireClickOut, VTS_NONE)
    //}}AFX_EVENT_MAP
END_EVENT_MAP()

The macro EVENT_CUSTOM associates the ClickOut event name with the member function FireClickOut and with its argument type definition. The ClickOut argument type definition is set to VTS_NONE, which indicates that the ClickOut event passes no arguments.

ClassWizard adds an inline function to the CCircCtrl class declaration. The FireClickOut function provides a type-safe call to fire the event:

class CCircCtrl : public COleControl
{
    ...
    //{{AFX_EVENT(CCircCtrl)
    void FireClickIn(OLE_XPOS_PIXELS x, OLE_YPOS_PIXELS y)
        {FireEvent(eventidClickIn,EVENT_PARAM(VTS_XPOS_PIXELS  VTS_YPOS_PIXELS),
    x, y);}
    void FireClickOut()
        {FireEvent(eventidClickOut,EVENT_PARAM(VTS_NONE));}
    //}}AFX_EVENT
    ...
}