Duilib布局及原理

来源:互联网 发布:win10修改mac地址无效 编辑:程序博客网 时间:2024/05/16 15:40


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的消息映射
0 0