假設創建的ocx工程名稱為AgentRest,要添加的事件為OnPreviewCallRequest。 1.AgentRest.idl文件中添加 [id(1)] OnPreviewCallRequest(long lCtrlID, BSTR lpCalls); [cpp] [ uuid(7BC09251-081A-4AAE-A757-18D603CE4800), helpstring("Event interface for AgentRest Control") ] dispinterface _DAgentRestEvents { properties: // Event interface has no properties methods: [id(1)] OnPreviewCallRequest(long lCtrlID, BSTR lpCalls); } 2.AgentRestCtrl.h和AgentRestCtrl.cpp [cpp] // Dispatch and event IDs public: enum { dispidSendEmailAttach = 193L, dispidReplyOnlineMessageByEmail = 192L, dispidReplyEmail = 1L, //事件 eventidOnPreviewCallRequest= 1L, }; public: //事件開始 void OnPreviewCallRequest(long lCtrlID, LPCTSTR lpCalls); [cpp] // Event map BEGIN_EVENT_MAP(CAgentRestCtrl, COleControl) EVENT_CUSTOM_ID("OnPreviewCallRequest", eventidOnPreviewCallRequest, OnPreviewCallRequest, VTS_I4 VTS_BSTR) END_EVENT_MAP() void CAgentRestCtrl::OnPreviewCallRequest(long lCtrlID, LPCTSTR lpCalls) { m_pDispatch->WriteLog(ERROR_EVENT, LOGINFO_EVENT_ONPREVIEWCALLREQUEST, lCtrlID, lpCalls); FireEvent(eventidOnPreviewCallRequest, EVENT_PARAM(VTS_I4 VTS_BSTR), lCtrlID, lpCalls); }