首页 > 其他 > 详细

DUILIB消息处理过程

时间:2018-12-17 18:26:14      阅读:142      评论:0      收藏:0      [点我收藏+]

DUILIB消息处理机制

方法一、

首先窗口基类创建 CWindowWnd->Create()

调用 CWindowWnd->RegisterWindowClass() 注册 CWindowWnd->__WndProc() 为本界面窗口消息处理函数

 __WndProc()调用 虚函数 CWindowWnd->HandleMessage() 处理消息

WinImplBase继承 CWindowWnd 并重写了 HandleMessage()处理消息 该函数拦截 WM_CREATE 、WM_MOUSEMOVE等常见消息,并转发至 该类对应的虚函数 WinImplBase::OnCreate(),WinImplBase::OnMouseMove()等 ,

之后WinImplBase::HandleMessage()函数调用 该类虚方法 WinImplBase::HandleCustomMessage()

此时我们可以自己重写窗口的 HandleCustomMessage(),OnCreate(), OnMouseMove()等 方法进行消息过程处理

 

最后WinImplBase::HandleMessage()函数调用该类的成员CPaintManagerUI  m_pm的MessageHandler()方法;

 在m_pm的MessageHandler()方法中首先调用了LRESULT lResult = static_cast<IMessageFilterUI*>(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);

 此时我们可以实现 IMessageFilterUI接口并调用CPaintManagerUI::AddPreMessageFilter()  添加到m_aMessageFilters过滤队列中,在IMessageFilterUI::MessageHandler(uMsg, wParam, lParam, bHandled);中处理消息

 之后调用了 static_cast<INotifyUI*>(m_aNotifiers[j])->Notify(*pMsg);

此时我们可以实现INotifyUI,调用CPaintManagerUI::AddNotifier,将自身加入Notifier队列。

方法 二、

CPaintManagerUI::MessageLoop() 消息泵  调用 CPaintManagerUI::TranslateMessage(const LPMSG pMsg)来进行分发消息

该函数会调用 该类 PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& /*lRes*/)

之后在PreMessageHandler() 中调用 LRESULT lResult = static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);

 

此时我们可以实现IMessageFilterUI接口并调用CPaintManagerUI::AddPreMessageFilter()  过滤队列中,通过此方法可以 在窗口处理之前 先对消息进行预处理

 

DUILIB消息处理过程

原文:https://www.cnblogs.com/guozht/p/10132999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!