Home | Overview | How Do I | Tutorial | Sample
This article discusses using ClassWizard to install event handlers for ActiveX controls in an ActiveX control container. The event handlers are used to receive notifications (from the control) of certain events and perform some action in response. This notification is called “firing” the event.
Note This article uses a dialog-based ActiveX control container project named Container and an embedded control named Circ2 as examples in the procedures and code.
Using the Message Maps tab in ClassWizard, you can create a map of events that can occur in your ActiveX control container application. This map, called an “event sink map,’’ is created and maintained by ClassWizard when you add event handlers to the control container class. Each event handler, implemented with an event map entry, maps a specific event to a container event handler member function. This event handler function is called when the specified event is fired by the ActiveX control object.
For more information on event sink maps, see Event Sink Maps in the Class Library Reference.
To create an event handler function
CContainerDlg
.IDC_CIRC2CTRL1
.
The Messages box displays a list of events that can be fired by the embedded ActiveX control. Any member function shown in bold already has handler functions assigned to it.
A suggested name for the handler function appears in the Member Functions box. For this example, use the suggested name.
CContainerDlg
or Close to close ClassWizard.When you use ClassWizard to add event handlers, an event sink map is declared and defined in your project. The following statements are added to the control .CPP file the first time an event handler is added. This code declares an event sink map for the dialog box class (in this case, CContainerDlg
):
BEGIN_EVENTSINK_MAP(CContainerDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CContainerDlg)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
As you use ClassWizard to add events, an event map entry (ON_EVENT) is added to the event sink map and an event handler function is added to the container’s implementation (.CPP) file.
The following example declares an event handler, called OnClickInCirc2Ctrl
, for the Circ2 control’s ClickIn event:
BEGIN_EVENTSINK_MAP(CContainerDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CContainerDlg)
ON_EVENT(CContainerDlg, IDC_CIRC2CTRL1, 1 /*
ClickIn */, OnClickInCirc2ctrl, VTS_I4 VTS_I4)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
In addition, the following template is added to the CContainerDlg
class implementation (.CPP) file for the event handler member function:
BOOL CContainerDlg::OnClickInCirc2ctrl1(OLE_XPOS_PIXELS nX, OLE_YPOS_PIXELS nY)
{
// use nX and nY here
}
For more information on event sink macros, see Event Sink Maps in the Class Library Reference.