#include "stdafx.h"#include "MsgHandler.h"// CMsgHandlerIMPLEMENT_DYNAMIC(CMsgHandler, CWnd)#define WM_EVENT_MESSAGE (WM_USER + 546)CMsgHandler::CMsgHandler(){m_pEventInterface = NULL;}CMsgHandler::~CMsgHandler(){Close();#ifdef MsgHandle_Track_MemoryCSingleLock lock(&m_cs, TRUE);//窗口销毁了,没有收到Post消息, 清除相应的EventData对象std::map<tagEventMsgData* , BOOL>::iterator itMap = m_mapEventData.begin();while (itMap != m_mapEventData.end()){if (itMap->second)delete itMap->first;++itMap;}m_mapEventData.clear();#endif}BEGIN_MESSAGE_MAP(CMsgHandler, CWnd)ON_MESSAGE(WM_EVENT_MESSAGE,OnEventMessage)END_MESSAGE_MAP()// CMsgHandler 消息处理程序BOOL CMsgHandler::Create(){Close();return CWnd::CreateEx(0,AfxRegisterWndClass(0),_T(""),WS_POPUP,CRect(0,0,1,1),NULL,0);}BOOL CMsgHandler::IsCreated(){if(::IsWindow(m_hWnd))return TRUE;elsereturn FALSE;}void CMsgHandler::Close(){if(::IsWindow(m_hWnd))DestroyWindow();}void CMsgHandler::SetEventInterface(CMsgHandlerEventInterface* pInterface){m_pEventInterface = pInterface;}void CMsgHandler::RaiseEvent(int nEvent,WPARAM wParam,LPARAM lParam){if (!GetSafeHwnd())return;if(m_pEventInterface){tagEventMsgData* pEvent = new tagEventMsgData;pEvent->nEvent = nEvent;pEvent->wParam = wParam;pEvent->lParam = lParam;#ifdef MsgHandle_Track_Memoryif (1){CSingleLock lock(&m_cs, TRUE);m_mapEventData[pEvent] = TRUE;}#endifPostMessage(WM_EVENT_MESSAGE,0,(LPARAM)pEvent);}}void CMsgHandler::SendEvent(int nEvent,WPARAM wParam,LPARAM lParam){if (!GetSafeHwnd())return;if(m_pEventInterface){tagEventMsgData* pEvent = new tagEventMsgData;pEvent->nEvent = nEvent;pEvent->wParam = wParam;pEvent->lParam = lParam;SendMessage(WM_EVENT_MESSAGE,0,(LPARAM)pEvent);}}LRESULT CMsgHandler::OnEventMessage(WPARAM wParam,LPARAM lParam){if(lParam != 0){tagEventMsgData* pEvent = (tagEventMsgData*)lParam;int nEvent = pEvent->nEvent;LPARAM lParam = pEvent->lParam;WPARAM wParam = pEvent->wParam;#ifdef MsgHandle_Track_Memoryif (1){CSingleLock lock(&m_cs, TRUE);m_mapEventData.erase(pEvent);}#endifSAFE_DELETE(pEvent);if(m_pEventInterface)m_pEventInterface->OnMsgEvent(nEvent,wParam,lParam);}return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。