谢谢您,不过没看明白,比如:
switch (dispidMember)
{
case 0x3f6:
OnScrollEvent();//here is my event handler
break;
...
}
dispidMember是怎样传给函数Invoke的呢,而OnScrollEvent是怎么用的呢?控件里发出Event的函数是什么?是否要用消息处理来获得控件发出的消息?谢谢
Using IDispEventSimpleImplSee Also
Event Handling and ATL | ATLEventHandling Sample
When using IDispEventSimpleImpl to handle events, you will need to:
Derive your class from IDispEventSimpleImpl.
Add an event sink map to your class.
Define _ATL_FUNC_INFO structures describing the events.
Add entries to the event sink map using the SINK_ENTRY_INFO macro.
Implement the methods that you're interested in handling.
Advise and unadvise the event source.
Example
The example below shows you how to handle the DocumentChange event fired by Word's Application object. This event is defined as a method on the ApplicationEvents dispinterface.
The example is from the ATLEventHandling sample.
[
uuid(000209F7-0000-0000-C000-000000000046),
hidden
]
dispinterface ApplicationEvents {
properties:
methods:
[id(0x00000001), restricted, hidden]
void Startup();
[id(0x00000002)]
void Quit();
[id(0x00000003)]
void DocumentChange();
};
The example uses #import to generate the required header files from Word's type library. If you want to use this example with other versions of Word, you must specify the correct mso dll file. For example, Office 2000 provides mso9.dll and OfficeXP provides mso.dll. This code is from stdafx.h.:
#pragma warning (disable : 4146)
#import "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\MSO97.DLL" raw_interfaces_only
#import "C:\PROGRAM FILES\COMMON FILES\MICROSOFT SHARED\VBA\VBEEXT1.OLB" raw_interfaces_only
#import "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\MSWORD8.OLB" rename("ExitWindows", "WordExitWindows") raw_interfaces_only
#pragma warning (default : 4146)
The only information from the type library actually used in this example is the CLSID of the Word Application object and the IID of the ApplicationEvents interface. This information is only used at compile time.
The following code appears in Simple.h. The relevant code is in bold:
// Declare structure for type information
extern _ATL_FUNC_INFO OnDocChangeInfo;
class ATL_NO_VTABLE CSimple :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CSimple, &CLSID_Simple>,
public IDispatchImpl<ISwitch, &IID_ISwitch, &LIBID_DISPEVENTLib>,
public IDispEventSimpleImpl</*nID =*/ 1, CSimple, &__uuidof(Word::ApplicationEvents)>
{
public:
CSimple()
{
}
// Event handler
// Note the __stdcall calling convention and
// dispinterface-style signature
void __stdcall OnDocChange()
{
// Get a pointer to the _Document interface on the active document
CComPtr<Word::_Document> pDoc;
m_pApp->get_ActiveDocument(&pDoc);
// Get the name from the active document
CComBSTR bstrName;
pDoc->get_Name(&bstrName);