1.Duilib分为几个大部分:
(1)控件
(2)容器(本质也是控件)
(3)UI构建解析器(XML解析)
(4)窗体管理器(消息循环,消息映射,消息处理,窗口管理等)
(5)渲染引擎
2.Win32消息路由如下:
消息产生。
系统将消息排列到其应该排放的线程消息队列中。
线程中的消息循环调用GetMessage(or PeekMessage)获取消息。
传送消息TranslateMessage and DispatchMessage to 窗口过程(Windows procedure)。
在窗口过程里进行消息处理.
3.DuiLib的消息处理原理:
DuiLib架构的消息处理也是遵从Win32消息处理过程的,但是在某些步骤间进行消息过滤。首先,第1、2和3步骤,DuiLib并不关心,依然是按Win32处理的过程。DuiLib对消息处理集中在CPaintManagerUI类中(也就是上面提到的窗体管理器)。DuiLib在发送到窗口过程的前和后都进行了消息过滤(也就是在GetMessage或PeekMessage之后进行了消息的处理过程,如消息删选)。
DuiLib的消息渠,也就是所谓的消息循环在CPaintManagerUI::MessageLoop()或者CWindowWnd::ShowModal()中实现。俩套代码的核心基本一致,以MessageLoop为例:
void CPaintManagerUI::MessageLoop(){
MSG msg = { 0 };
while( ::GetMessage(&msg, NULL, 0, 0) ) {
// CPaintManagerUI::TranslateMessage进行消息过滤
if( !CPaintManagerUI::TranslateMessage(&msg) ) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
}
3和4之间,DuiLib调用CPaintManagerUI::TranslateMessage做了过滤,类似MFC的PreTranlateMessage。
4.俩个地方可以截获消息:
(1)实现IMessageFilterUI接口,调用CPaintManagerUI:: AddPreMessageFilter,进行消息发送到窗口过程前的过滤。
(2)重载HandleMessage函数,当消息发送到窗口过程中时,最先进行过滤。
5.又多了两种消息处理的方式:
(1)实现INotifyUI,调用CPaintManagerUI::AddNotifier,将自身加入Notifier队列。
(2)添加消息代理(其实就是将成员函数最为回到函数加入),MakeDelegate(this, &CFrameWindowWnd::OnAlphaChanged);,当程序某个地方调用了 CPaintManagerUI::SendNotify,并且Msg.pSender正好是注册的this,我们的类成员回调函数将被调用。
6.总结,DuiLib消息响应方式:
(1)实现IMessageFilterUI接口,调用CPaintManagerUI::AddPreMessageFilter,进行消息发送到窗口过程前的过滤。
(2)重载HandleMessage函数,当消息发送到窗口过程中时,最先进行过滤。
(3)实现INotifyUI,调用CPaintManagerUI::AddNotifier,将自身加入Notifier队列。
(4)添加消息代理(其实就是将成员函数最为回到函数加入),MakeDelegate(this, &CFrameWindowWnd::OnAlphaChanged);,当程序某个地方调用了 CPaintManagerUI::SendNotify,并且Msg.pSender正好是this,我们的类成员回调函数将被调用。
(5)重载父类:WindowImplBase的虚函数
(6)重载父类:WindowImplBase::HandleCustomMessage函数
(7)使用类似MFC的消息映射
duilib架构 duilib原理
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
duilib开发(八):duilib 实现 table switchduilib 控件 自动换行 #include f5
-
Duilib corner属性
Duilib corner 用法详细介绍
corner 九宫格 .net 实现原理 -
Duilib 虚表
在duilib的实际应用过程中我们可能会遇见很大的数据量需要展示。此时如果
duilib 虚表 大数据 数据 控件 -
Duilib ListContain 扩展
源码下载地址:https://share.weiyun.com/5TSf5mJ通过对listConta
Duilib listContain扩展 控件 git 源码下载 -
Duilib 内嵌xml
Duilib 中内嵌Xml
Duilib 内嵌入xml xml