You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# ActiveX Control Containers: Handling Events from an ActiveX Control
8
8
9
-
This article discusses using the [Class Wizard](reference/mfc-class-wizard.md) 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.
9
+
This article discusses using the **Properties** window 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.
10
10
11
11
>[!IMPORTANT]
12
12
> 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](activex-controls.md).
13
13
14
14
> [!NOTE]
15
15
> 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.
16
16
17
-
Using the Events button in the [Class Wizard](reference/mfc-class-wizard.md), 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.
17
+
Using the Events button in the **Properties** window, 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.
18
18
19
19
For more information on event sink maps, see [Event Sink Maps](../mfc/reference/event-sink-maps.md) in the *Class Library Reference*.
20
20
21
21
## <aname="_core_event_handler_modifications_to_the_project"></a> Event Handler Modifications to the Project
22
22
23
-
When you use the [Class Wizard](reference/mfc-class-wizard.md) 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`):
23
+
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`):
As you use the [Class Wizard](reference/mfc-class-wizard.md) 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.
28
+
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.
29
29
30
30
The following example declares an event handler, called `OnClickInCircCtrl`, for the Circ control's `ClickIn` event:
31
31
@@ -41,11 +41,11 @@ For more information on event sink macros, see [Event Sink Maps](../mfc/referenc
41
41
42
42
1. From Class View, select the dialog class that contains the ActiveX control. For this example, use `CContainerDlg`.
43
43
44
-
1. In the [Class Wizard](reference/mfc-class-wizard.md), click the **Events** button.
44
+
1. In the **Properties** window, click the **Events** button.
45
45
46
-
1. In the [Class Wizard](reference/mfc-class-wizard.md), select the control ID of the embedded ActiveX control. For this example, use `IDC_CIRCCTRL1`.
46
+
1. In the **Properties** window, select the control ID of the embedded ActiveX control. For this example, use `IDC_CIRCCTRL1`.
47
47
48
-
The [Class Wizard](reference/mfc-class-wizard.md) 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.
48
+
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.
49
49
50
50
1. Select the event you want the dialog class to handle. For this example, select **Click**.
The [Class Wizard](reference/mfc-class-wizard.md) and Class View assist in maintaining dispatch maps. When you add a new method or property to a class, Visual C++ adds a corresponding `DISP_FUNCTION` or `DISP_PROPERTY` macro with parameters indicating the class name, external and internal names of the method or property, and data types.
28
+
The [Class Wizard](reference/mfc-class-wizard.md) and Class View assist in maintaining dispatch maps. When you add a new method or property to a class, Visual Studio adds a corresponding `DISP_FUNCTION` or `DISP_PROPERTY` macro with parameters indicating the class name, external and internal names of the method or property, and data types.
29
29
30
30
The **Add Class** dialog box also simplifies the declaration of Automation classes and the management of their properties and operations. When you use the Add Class dialog box to add a class to your project, you specify its base class. If the base class allows Automation, the Add Class dialog box displays controls you use to specify whether the new class should support Automation, whether it is "OLE creatable" (that is, whether objects of the class can be created on a request from a COM client), and the external name for the COM client to use.
@@ -31,7 +31,7 @@ The procedures use the following names and values:
31
31
32
32
1. Add a class for your dialog box. See [Adding a Class](../ide/adding-a-class-visual-cpp.md) for more information.
33
33
34
-
1. In **Class View**, select the document class (CDisplayDialogDoc). In the **Properties** window, click the **Events** button. Double-click the ID of the menu command (ID_VIEW_TEST) in the left pane of the **Properties** window and select **Command**. In the right pane, click the down arrow and select **\<Add> OnViewTest**.
34
+
1. In **Class View**, select the document class (CDisplayDialogDoc). In the [Class Wizard](reference/mfc-class-wizard.md), click the **Events** button. Double-click the ID of the menu command (ID_VIEW_TEST) in the left pane of the [Class Wizard](reference/mfc-class-wizard.md) and select **Command**. In the right pane, click the down arrow and select **\<Add> OnViewTest**.
35
35
36
36
If you added the menu command to the mainframe of an MDI application, select the application class (CDisplayDialogApp) instead.
To customize the Application button, open it in the **Properties** window, modify its properties, and then preview the ribbon control.
13
+
To customize the Application button, open it in the [Class Wizard](reference/mfc-class-wizard.md), modify its properties, and then preview the ribbon control.
14
14
15
15
### To open the Application button in the [Class Wizard](reference/mfc-class-wizard.md)
To customize the Quick Access Toolbar, open it in the **Properties** window, modify its commands, and then preview the ribbon control.
13
+
To customize the Quick Access Toolbar, open it in the [Class Wizard](reference/mfc-class-wizard.md), modify its commands, and then preview the ribbon control.
14
14
15
15
### To open the Quick Access Toolbar in the [Class Wizard](reference/mfc-class-wizard.md)
16
16
@@ -31,7 +31,7 @@ The following table defines the properties of the Quick Access Toolbar.
31
31
32
32
#### To add or remove commands on the Quick Access Toolbar
33
33
34
-
1. In the **Properties** window, click **QAT Items**, and then click the ellipsis button **(...)**.
34
+
1. In the [Class Wizard](reference/mfc-class-wizard.md), click **QAT Items**, and then click the ellipsis button **(...)**.
35
35
36
36
1. In the **QAT Items Editor** dialog box, use the **Add** and **Remove** buttons to modify the list of commands on the Quick Access Toolbar.
Now that you have added the ClickIn custom event using the Add Event Wizard, you must decide when this event is to be fired. You do this by calling `FireClickIn` when the appropriate action occurs. For this discussion, the control uses the `InCircle` function inside a WM_LBUTTONDOWN message handler to fire the ClickIn event when a user clicks inside a circular or elliptical region. The following procedure adds the WM_LBUTTONDOWN handler.
59
+
Now that you have added the ClickIn custom event using the Add Event Wizard, you must decide when this event is to be fired. You do this by calling `FireClickIn` when the appropriate action occurs. For this discussion, the control uses the `InCircle` function inside a `WM_LBUTTONDOWN` message handler to fire the ClickIn event when a user clicks inside a circular or elliptical region. The following procedure adds the `WM_LBUTTONDOWN` handler.
60
60
61
61
#### To add a message handler with the Add Event Wizard
62
62
63
63
1. Load your control's project.
64
64
65
-
1. In Class View, select your ActiveX control class.
65
+
1. In **Class View**, select your ActiveX control class.
66
66
67
-
1. In the [Class Wizard](reference/mfc-class-wizard.md), click the **Messages**button.
67
+
1. In [Class Wizard](reference/mfc-class-wizard.md), click the **Messages**tab.
68
68
69
69
The [Class Wizard](reference/mfc-class-wizard.md) displays a list of messages that can be handled by the ActiveX control. Any message shown in bold already has a handler function assigned to it.
70
70
71
-
1. From the [Class Wizard](reference/mfc-class-wizard.md), select the message you want to handle. For this example, select WM_LBUTTONDOWN.
71
+
1. From the [Class Wizard](reference/mfc-class-wizard.md), select the message you want to handle. For this example, select `WM_LBUTTONDOWN`.
72
72
73
73
1. From the drop-down list box on the right, select **\<Add> OnLButtonDown**.
74
74
75
-
1. Double-click the new handler function in Class View to jump to the message handler code in the implementation (.CPP) file of your ActiveX control.
75
+
1. Double-click the new handler function in **Class View** to jump to the message handler code in the implementation (.CPP) file of your ActiveX control.
76
76
77
-
The following code sample calls the `InCircle` function every time the left mouse button is clicked within the control window. This sample can be found in the WM_LBUTTONDOWN handler function, `OnLButtonDown`, in the [Circ sample](../overview/visual-cpp-samples.md) abstract.
77
+
The following code sample calls the `InCircle` function every time the left mouse button is clicked within the control window. This sample can be found in the `WM_LBUTTONDOWN` handler function, `OnLButtonDown`, in the [Circ sample](../overview/visual-cpp-samples.md) abstract.
You can use the [Class Wizard](reference/mfc-class-wizard.md)to add a message handler (a member function that handles Windows messages) to a class and map Windows messages to the message handler. You can also add [an event handler for any dialog box control](../../windows/adding-event-handlers-for-dialog-box-controls.md).
10
+
You can use the [Class Wizard](reference/mfc-class-wizard.md) or the **Properties** window in **CLass View**to add a message handler (a member function that handles Windows messages) to a class and map Windows messages to the message handler. You can also add [an event handler for any dialog box control](../../windows/adding-event-handlers-for-dialog-box-controls.md).
11
11
12
-
By using the Class Wizard to define message- and event-handling functions, you can automatically update the message-dispatch table (or message map) and your class header file.
12
+
By using the Class Wizard or Properties window to define message- and event-handling functions, you can automatically update the message-dispatch table (or message map) and your class header file.
13
13
14
14
> [!NOTE]
15
15
> You can add a message handler to an ATL class using the Class Wizard; however, some results may vary. For more information, see the ATL topic [Adding an ATL Message Handler](../../atl/adding-an-atl-message-handler.md).
Copy file name to clipboardExpand all lines: docs/mfc/reference/ccmdui-class.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ class CCmdUI
41
41
42
42
`CCmdUI` does not have a base class.
43
43
44
-
When a user of your application pulls down a menu, each menu item needs to know whether it should be displayed as enabled or disabled. The target of a menu command provides this information by implementing an ON_UPDATE_COMMAND_UI handler. For each of the command user-interface objects in your application, use the [Class Wizard](mfc-class-wizard.md) to create a message-map entry and function prototype for each handler.
44
+
When a user of your application pulls down a menu, each menu item needs to know whether it should be displayed as enabled or disabled. The target of a menu command provides this information by implementing an ON_UPDATE_COMMAND_UI handler. For each of the command user-interface objects in your application, use the [Class Wizard](mfc-class-wizard.md)or Properties window in Class View to create a message-map entry and function prototype for each handler.
45
45
46
46
When the menu is pulled down, the framework searches for and calls each ON_UPDATE_COMMAND_UI handler, each handler calls `CCmdUI` member functions such as `Enable` and `Check`, and the framework then appropriately displays each menu item.
@@ -21,7 +21,7 @@ Any dialog-based application, by definition, is forms based. A dialog-based appl
21
21
22
22
The base class for form-based applications is [CFormView](cformview-class.md). If your application has database support, then you can also select any class that derives from `CFormView`. A form is any window derived from `CFormView` or from any class that inherits from `CFormView`.
23
23
24
-
Even if you use a base class such as [CView](cview-class.md), you can later make your applications forms-based by [adding an MFC class](adding-an-mfc-class.md) derived from `CFormView` and checking the **Generate DocTemplate resources** checkbox in the [MFC Class Wizard](document-template-strings-mfc-add-class-wizard.md).
24
+
Even if you use a base class such as [CView](cview-class.md), you can later make your applications forms-based by [adding an MFC class](adding-an-mfc-class.md) derived from `CFormView`.
25
25
26
26
Once you finish with the wizard, your project opens, and if you selected `CFormView` (or a class that inherits from `CFormView`) as your base class or if you created a dialog-based application, Visual C++ opens the dialog editor. At this point, you are ready to design your first form.
0 commit comments