Click to open or copy the ATLEvent Handling project files.
This sample demonstrates the use of IDispEventImpl and IDispEventSimpleImpl to handle events fired by Microsoft Word.
The sample consists of an ATL project that includes two COM classes, CSimple and CNotSoSimple. These classes represent COM objects that display a message box in response to document change events fired by Microsoft Word. CSimple shows how to handle events using ATL's IDispEventSimpleImpl class template, and CNotSoSimple shows how to handle events using ATL's IDispEventImpl class template. The code in the two classes is identical except for the differences caused by the use of the different ATL templates.
Note This sample requires Microsoft Word.
To Run This Sample
You'll see a dialog box with a drop-down list allowing you to run the test using IDispEventImpl or IDispEventSimpleImpl. Select one of these items then click the Start button. If Microsoft Word is installed on your computer, a new instance will be loaded and the test component will start to receive events sent by Word whenever the active document changes.
You can trigger events by creating new documents, loading documents, or switching to a different document using Word's Window menu. Each time the document changes, a message box will be displayed indicating which component is receiving the events and the name of the newly active document. You can disconnect the event handler from the instance of Word by using the Stop button on the MFCClient dialog box, by changing the selection of the drop-down list, or by closing Word.
Dismiss the sample application using the OK or Cancel command buttons or the dialog box's Close button.
This sample uses the following keywords:
_ATL_FUNC_INFO, BEGIN_SINK_MAP, END_SINK_MAP, SINK_ENTRY_EX, SINK_ENTRY_INFO, IDispEventImpl, IDispEventSimpleImpl, IDispEventSimpleImpl::DispEventAdvise, IDispEventSimpleImpl::DispEventUnadvise