Firing the ClickIn Event

Now that the ClickIn event has been declared, it can be fired. The control itself determines when a custom event should be fired. In this example, the ClickIn event fires when the user clicks the left mouse button with the insertion point inside the control circle.

The code that fires the ClickIn event should be triggered when a WM_LBUTTONDOWN message is received from Windows. The Circle control already has a message handler function defined for WM_LBUTTONDOWN — the OnLButtonDown function in CIRCCTL.CPP.

Add the following lines to change OnLButtonDown to fire the ClickIn event:

        // Fire the ClickIn event
        FireClickIn(point.x, point.y);

as shown in the following code example:

void CCircCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
    CDC* pdc;
    
    // Flash the color of the control if within the ellipse.
    if (InCircle(point))
    {
        pdc = GetDC();
        FlashColor(pdc);
        ReleaseDC(pdc);

       // Fire the ClickIn event
        FireClickIn(point.x, point.y);
    }

    COleControl::OnLButtonDown(nFlags, point);
}

Modifying OnLButtonDown to fire the event requires a call to the FireClickIn function. The call to FireClickIn is made only if the InCircle function returns TRUE, which means that the insertion point is within the circle.