Skip to content

Latest commit

 

History

History
59 lines (35 loc) · 4.35 KB

activex-control-containers-handling-events-from-an-activex-control.md

File metadata and controls

59 lines (35 loc) · 4.35 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: ActiveX Control Containers: Handling Events from an ActiveX Control
ActiveX Control Containers: Handling Events from an ActiveX Control
09/12/2018
event handlers [MFC], ActiveX controls
ActiveX control containers [MFC], event sinks
event handling [MFC], ActiveX controls
ON_EVENT macro [MFC]
ActiveX controls [MFC], events [MFC]
END_EVENTSINK_MAP macro, using
events [MFC], ActiveX controls
BEGIN_EVENTSINK_MAP macro
f9c106db-052f-4e32-82ad-750646aa760b

ActiveX Control Containers: Handling Events from an ActiveX Control

This article discusses using the Properties window (in Class View) 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.

Important

ActiveX is a legacy technology that should not be used for new development. For more information about modern technologies that supersede ActiveX, see ActiveX Controls.

Note

This article uses a dialog-based ActiveX control container project named Container and an embedded control named Circ as examples in the procedures and code.

Using the Events button in the Properties window (in Class View), 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 Visual C++ 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.

Event Handler Modifications to the Project

When you use the Properties window 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):

[!code-cppNVC_MFC_AxCont#8] [!code-cppNVC_MFC_AxCont#9]

As you use the Properties window 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 OnClickInCircCtrl, for the Circ control's ClickIn event:

[!code-cppNVC_MFC_AxCont#10]

In addition, the following template is added to the CContainerDlg class implementation (.CPP) file for the event handler member function:

[!code-cppNVC_MFC_AxCont#11]

For more information on event sink macros, see Event Sink Maps in the Class Library Reference.

To create an event handler function

  1. From Class View, select the dialog class that contains the ActiveX control. For this example, use CContainerDlg.

  2. In the Properties window, click the Events button.

  3. In the Properties window, select the control ID of the embedded ActiveX control. For this example, use IDC_CIRCCTRL1.

    The Properties window 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.

  4. Select the event you want the dialog class to handle. For this example, select Click.

  5. From the drop-down list box on the right, select <Add> ClickCircctrl1.

  6. Double-click the new handler function from Class View to jump to the event handler code in the implementation (.CPP) file of CContainerDlg.

See also

ActiveX Control Containers