假设创建的ocx工程名称为AgentRest,要添加的事件为OnPreviewCallRequest。
1.AgentRest.idl文件中添加 [id(1)] OnPreviewCallRequest(long lCtrlID, BSTR lpCalls);
[ 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
// Dispatch and event IDspublic: enum { dispidSendEmailAttach = 193L, dispidReplyOnlineMessageByEmail = 192L, dispidReplyEmail = 1L,//事件 eventidOnPreviewCallRequest= 1L, };public: //事件开始 void OnPreviewCallRequest(long lCtrlID, LPCTSTR lpCalls);
// Event mapBEGIN_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);}