duilib帮助

1.窗口基类:见介绍

顺便贴下出来,留底。

.h

 1 class WindowImplBase : public CWindowWnd, public INotifyUI, public IMessageFilterUI, public IDialogBuilderCallback, public SkinChangedReceiver
 2 {
 3 public:
 4     WindowImplBase();
 5     virtual ~WindowImplBase();
 6
 7     virtual void OnFinalMessage(HWND hWnd);
 8
 9     virtual void Init();
10
11     virtual CControlUI* CreateControl(LPCTSTR pstrClass);
12
13     virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
14
15     virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
16
17     virtual LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
18
19     virtual LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
20
21     virtual LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
22
23     virtual LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
24
25     virtual LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
26
27     virtual LRESULT OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
28
29     virtual LRESULT OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
30
31     virtual LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
32
33     virtual LRESULT OnMoving(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
34
35     virtual LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
36
37     virtual LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
38
39     virtual LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
40
41     virtual LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
42
43     virtual LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
44
45     virtual LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
46
47     virtual LRESULT OnNCLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
48
49     virtual LRESULT OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
50
51     virtual LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
52
53     virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
54
55     virtual LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
56
57 protected:
58     virtual tString GetSkinFolder();
59     virtual tString GetSkinFile() = 0;
60
61     virtual LRESULT ResponseDefaultKeyEvent(WPARAM wParam, bool& bHandled);
62
63 protected:
64     CPaintManagerUI        paint_manager_;
65
66 };

.cpp

  1 WindowImplBase::WindowImplBase()
  2 {}
  3
  4 WindowImplBase::~WindowImplBase()
  5 {}
  6
  7 CControlUI* WindowImplBase::CreateControl(LPCTSTR pstrClass)
  8 {
  9     return NULL;
 10 }
 11
 12 void WindowImplBase::OnFinalMessage(HWND /*hWnd*/)
 13 {
 14     paint_manager_.RemovePreMessageFilter(this);
 15     paint_manager_.RemoveNotifier(this);
 16     paint_manager_.ReapObjects(paint_manager_.GetRoot());
 17 }
 18
 19 void WindowImplBase::Init()
 20 {}
 21
 22 LRESULT WindowImplBase::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
 23 {
 24     bHandled = FALSE;
 25     return 0;
 26 }
 27
 28 LRESULT WindowImplBase::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
 29 {
 30     bHandled = FALSE;
 31     return 0;
 32 }
 33
 34 #if defined(WIN32) && !defined(UNDER_CE)
 35 LRESULT WindowImplBase::OnNcActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
 36 {
 37     if( ::IsIconic(*this) ) bHandled = FALSE;
 38     return (wParam == 0) ? TRUE : FALSE;
 39 }
 40
 41 LRESULT WindowImplBase::OnNcCalcSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
 42 {
 43     return 0;
 44 }
 45
 46 LRESULT WindowImplBase::OnNcPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
 47 {
 48     return 0;
 49 }
 50
 51 LRESULT WindowImplBase::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 52 {
 53     POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);
 54     ::ScreenToClient(*this, &pt);
 55
 56     RECT rcClient;
 57     ::GetClientRect(*this, &rcClient);
 58
 59     //if( !::IsZoomed(*this) ) {
 60     //    RECT rcSizeBox = paint_manager_.GetSizeBox();
 61     //    if( pt.y < rcClient.top + rcSizeBox.top ) {
 62     //        if( pt.x < rcClient.left + rcSizeBox.left ) return HTTOPLEFT;
 63     //        if( pt.x > rcClient.right - rcSizeBox.right ) return HTTOPRIGHT;
 64     //        return HTTOP;
 65     //    }
 66     //    else if( pt.y > rcClient.bottom - rcSizeBox.bottom ) {
 67     //        if( pt.x < rcClient.left + rcSizeBox.left ) return HTBOTTOMLEFT;
 68     //        if( pt.x > rcClient.right - rcSizeBox.right ) return HTBOTTOMRIGHT;
 69     //        return HTBOTTOM;
 70     //    }
 71     //    if( pt.x < rcClient.left + rcSizeBox.left ) return HTLEFT;
 72     //    if( pt.x > rcClient.right - rcSizeBox.right ) return HTRIGHT;
 73     //}
 74
 75     RECT rcCaption = paint_manager_.GetCaptionRect();
 76     if( pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right  77         && pt.y >= rcCaption.top && pt.y < rcCaption.bottom ) {
 78             CControlUI* pControl = static_cast<CControlUI*>(paint_manager_.FindControl(pt));
 79             if( pControl && _tcsicmp(pControl->GetClass(), _T("ButtonUI")) != 0 &&
 80                 _tcsicmp(pControl->GetClass(), _T("OptionUI")) != 0 )
 81                 return HTCAPTION;
 82     }
 83
 84     return HTCLIENT;
 85 }
 86
 87 LRESULT WindowImplBase::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 88 {
 89     MONITORINFO oMonitor = {};
 90     oMonitor.cbSize = sizeof(oMonitor);
 91     ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
 92     CRect rcWork = oMonitor.rcWork;
 93     rcWork.Offset(-rcWork.left, -rcWork.top);
 94
 95     LPMINMAXINFO lpMMI = (LPMINMAXINFO) lParam;
 96     lpMMI->ptMaxPosition.x    = rcWork.left;
 97     lpMMI->ptMaxPosition.y    = rcWork.top;
 98     lpMMI->ptMaxSize.x        = rcWork.right;
 99     lpMMI->ptMaxSize.y        = rcWork.bottom;
100
101     bHandled = FALSE;
102     return 0;
103 }
104
105 LRESULT WindowImplBase::OnMouseWheel(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
106 {
107     bHandled = FALSE;
108     return 0;
109 }
110 #endif
111
112 LRESULT WindowImplBase::OnSetFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
113 {
114     bHandled = FALSE;
115     return 0;
116 }
117
118 LRESULT WindowImplBase::OnLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
119 {
120     bHandled = FALSE;
121     return 0;
122 }
123
124 LRESULT WindowImplBase::OnNCLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
125 {
126     bHandled = FALSE;
127     return 0;
128 }
129
130 LRESULT WindowImplBase::OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
131 {
132     bHandled = FALSE;
133     return 0;
134 }
135
136 LRESULT WindowImplBase::OnLButtonUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
137 {
138     bHandled = FALSE;
139     return 0;
140 }
141
142 LRESULT WindowImplBase::OnKeyDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
143 {
144     bHandled = FALSE;
145     return 0;
146 }
147
148 LRESULT WindowImplBase::OnKillFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
149 {
150     bHandled = FALSE;
151     return 0;
152 }
153
154 LRESULT WindowImplBase::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
155 {
156     SIZE szRoundCorner = paint_manager_.GetRoundCorner();
157 #if defined(WIN32) && !defined(UNDER_CE)
158     if( !::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0) ) {
159         CRect rcWnd;
160         ::GetWindowRect(*this, &rcWnd);
161         rcWnd.Offset(-rcWnd.left, -rcWnd.top);
162         rcWnd.right++; rcWnd.bottom++;
163         HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
164         ::SetWindowRgn(*this, hRgn, TRUE);
165         ::DeleteObject(hRgn);
166     }
167 #endif
168     bHandled = FALSE;
169     return 0;
170 }
171
172 LRESULT WindowImplBase::OnMoving(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
173 {
174     bHandled = FALSE;
175     return 0;
176 }
177
178 LRESULT WindowImplBase::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
179 {
180     if (wParam == SC_CLOSE){
181         bHandled = TRUE;
182         return 0;
183     }
184 #if defined(WIN32) && !defined(UNDER_CE)
185     BOOL bZoomed = ::IsZoomed(*this);
186     LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
187     if( ::IsZoomed(*this) != bZoomed ){
188     }
189 #else
190     LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
191 #endif
192     return lRes;
193 }
194
195 tString WindowImplBase::GetSkinFolder()
196 {
197     return tString(CPaintManagerUI::GetInstancePath()) + _T("Skins\\");
198 }
199
200 LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
201 {
202     LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
203     styleValue &= ~WS_CAPTION;
204     ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
205     RECT rcClient;
206     ::GetClientRect(*this, &rcClient);
207     ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, 208         rcClient.bottom - rcClient.top, SWP_FRAMECHANGED);
209
210     paint_manager_.Init(m_hWnd);
211     paint_manager_.AddPreMessageFilter(this);
212
213     CDialogBuilder builder;
214
215     paint_manager_.SetResourcePath(GetSkinFolder().c_str());
216
217 #if USE(ZIP_SKIN)
218
219 #if defined(WIN32) && !defined(UNDER_CE)
220     static bool resource_unzipped = false;
221     if (!resource_unzipped)
222     {
223         resource_unzipped = true;
224         paint_manager_.SetResourceZip(GlobalVariable::kResourceSkinZipFileName);
225         paint_manager_.UnzipResource();
226         paint_manager_.SetResourceZip(GlobalVariable::kNullString);
227     }
228     tString tstrSkin = paint_manager_.GetResourcePath();
229     tstrSkin += GetSkinFile();
230 #else
231     paint_manager_.SetResourceZip(GlobalVariable::kResourceSkinZipFileName);
232     tString tstrSkin = GetSkinFile();
233 #endif
234
235 #else
236     tString tstrSkin = paint_manager_.GetResourcePath();
237     tstrSkin += GetSkinFile();
238 #endif
239     CControlUI* pRoot = builder.Create(tstrSkin.c_str(), (UINT)0, this, &paint_manager_);
240     paint_manager_.AttachDialog(pRoot);
241     paint_manager_.AddNotifier(this);
242 #endif
243
244     Init();
245     return 0;
246 }
247
248 LRESULT WindowImplBase::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
249 {
250     bHandled = FALSE;
251     return 0;
252 }
253
254 LRESULT WindowImplBase::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
255 {
256     LRESULT lRes = 0;
257     BOOL bHandled = TRUE;
258     switch (uMsg)
259     {
260     case WM_CREATE:            lRes = OnCreate(uMsg, wParam, lParam, bHandled); break;
261     case WM_CLOSE:            lRes = OnClose(uMsg, wParam, lParam, bHandled); break;
262     case WM_DESTROY:        lRes = OnDestroy(uMsg, wParam, lParam, bHandled); break;
263 #if defined(WIN32) && !defined(UNDER_CE)
264     case WM_NCACTIVATE:        lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break;
265     case WM_NCCALCSIZE:        lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;
266     case WM_NCPAINT:        lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;
267     case WM_NCHITTEST:        lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;
268     case WM_GETMINMAXINFO:    lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled); break;
269     case WM_MOUSEWHEEL:        lRes = OnMouseWheel(uMsg, wParam, lParam, bHandled); break;
270 #endif
271     case WM_SIZE:            lRes = OnSize(uMsg, wParam, lParam, bHandled); break;
272     case WM_MOVING:            lRes = OnMoving(uMsg, wParam, lParam, bHandled); break;
273     case WM_SYSCOMMAND:        lRes = OnSysCommand(uMsg, wParam, lParam, bHandled); break;
274     case WM_KEYDOWN:        lRes = OnKeyDown(uMsg, wParam, lParam, bHandled); break;
275     case WM_KILLFOCUS:        lRes = OnKillFocus(uMsg, wParam, lParam, bHandled); break;
276     case WM_SETFOCUS:        lRes = OnSetFocus(uMsg, wParam, lParam, bHandled); break;
277     case WM_LBUTTONUP:        lRes = OnLButtonUp(uMsg, wParam, lParam, bHandled); break;
278     case WM_LBUTTONDOWN:    lRes = OnLButtonDown(uMsg, wParam, lParam, bHandled); break;
279     case WM_MOUSEMOVE:        lRes = OnMouseMove(uMsg, wParam, lParam, bHandled); break;
280     case WM_NCLBUTTONDOWN:    lRes = OnNCLButtonDown(uMsg, wParam, lParam, bHandled); break;
281     default:                bHandled = FALSE; break;
282     }
283     if (bHandled) return lRes;
284
285     lRes = HandleCustomMessage(uMsg, wParam, lParam, bHandled);
286     if (bHandled) return lRes;
287
288     if (paint_manager_.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
289     return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
290 }
291
292 LRESULT WindowImplBase::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
293 {
294     if (uMsg == WM_KEYDOWN)
295     {
296         switch (wParam)
297         {
298         case VK_RETURN:
299         case VK_ESCAPE:
300             return ResponseDefaultKeyEvent(wParam, bHandled);
301         default:
302             break;
303         }
304     }
305     return FALSE;
306 }
307
308 LRESULT WindowImplBase::ResponseDefaultKeyEvent(WPARAM wParam, bool& bHandled)
309 {
310     if (wParam == VK_RETURN)
311     {
312         return FALSE;
313     }
314     else if (wParam == VK_ESCAPE)
315     {
316         Close();
317         return TRUE;
318     }
319
320     return FALSE;
321 }

代码出处:http://www.who1753.com/duilib-windowimplbase.html

2.属性列表.xml

有时间把它精简后再帖出来。。。原xml 900+ 行,吓死爹了

时间: 2024-10-07 07:46:23

duilib帮助的相关文章

Duilib中的消息泵和虚拟窗口

Duilib中的消息泵和虚拟窗口 一.消息泵的结构 CNotifyPump类是构建Duilib消息泵的根父类,要使用消息泵机制的窗口类应该从该类继承.在继承关系的基础上,通过DUI_DECLARE_MESSAGE_MAP.DUI_BEGIN_MESSAGE_MAP.DUI_END_MESSAGE_MAP.DUI_ON_MSGTYPE.DUI_ON_MSGTYPE_CTRNAME.DUI_ON_CLICK_CTRNAME.DUI_ON_SELECTCHANGED_CTRNAME.DUI_ON_KI

Duilib中为RichEdit\Edit控件添加自定义右键菜单

前言 Duilib中的RichEdit控件在使用中发现,基本上对复制.粘贴.剪切等快捷方式都是支持的,不过唯一缺点是没有右键菜单,感觉不够好,于是就想着加上右键菜单. 右键菜单基本思路是,在RichEdit的消息处理函数中对鼠标的右键消息处理,发送一个自定义的Notify消息出来,主窗口中受到这个消息后弹出自己的右键菜单. 实现方法 第一步:把鼠标右键消息转发出来 MessageHandler中修改原有代码 bool bWasHandled = true; if( (uMsg >= WM_MOU

duilib 界面库 实现timer定时器

看了大神介绍的duilib感觉已被同龄人狠狠地甩在背后.所以痛下决心,之后要多花时间写代码. 大神教程传送门: http://www.cnblogs.com/Alberl/p/3341956.html 现在的问题是想基于duilib实现一个timer定时器.工程基础大概是在 http://www.cnblogs.com/Alberl/p/3343763.html 因为自己的东西是基于大神的东西写的,所以要把大神的教程看得差不多才知道我在说什么.O(∩_∩)O~~ 前台大概长这个样子: 稍微修改了

Duilib学习(一)

#pragma once #include <UIlib.h> using namespace DuiLib; #ifdef _DEBUG # ifdef _UNICODE # pragma comment(lib, "DuiLib_ud.lib") # else # pragma comment(lib, "DuiLib_d.lib") # endif #else # ifdef _UNICODE # pragma comment(lib, "

Duilib源码分析(五)UI布局—Layout

接下来,继续分析duilib之UI布局Layout,目前提供的布局有:VerticalLayout.HorizontalLayout.TileLayout.TabLayout.ChildLayout分别为垂直布局.水平布局.平铺布局.TAB布局.子窗体布局: 一般项目中用得比较多的是垂直布局.水平布局,我们将分别分析各布局: VerticalLayout:垂直布局,继承于CContainerUI容器UI类:而CContainerUI也继承于CControlUI,故VerticalLayout实际

duilib库分析: 消息流程分析

转 看下CWindowWnd类与CPaintManagerUI类是咋进行消息分发的吧. 1. 先看下CPaintManagerUI类的MessageLoop函数: void CPaintManagerUI::MessageLoop() { MSG msg = { 0 }; while( ::GetMessage(&msg, NULL, 0, 0) ) {    // 获取消息 if( !CPaintManagerUI::TranslateMessage(&msg) ) { // 消息过滤

分享个Duilib中基于wke的浏览器控件

概述 wke是基于谷歌chrome浏览器源代码的裁剪版本,大小仅仅只有10M左右,无需依赖其他的扩展库(跟CEF的一大堆大约40M的DLL来比简直爽呆了),就可以在本地使用谷歌内核快速加载网页.网上也有基于wke在Duilib 上扩展的控件代码,其实wke头文件挺清楚的了,接口一目了然,特别是JS与C++交互的函数更是容易看懂,也没什么难的,你也可以做到的. 代码 毕竟是裁剪库,有的功能还是没有接口来处理的(比如网页加载前.页面跳转.菜单消息--),头文件代码: #ifndef __UIWKEW

Duilib教程-自动布局2

在上一节中,我简单介绍了控件随父LAYOUT自由移动的设置.在这一节,我将介绍一种常见的情况:嵌入窗口. 在项目中,我们很少会100%的编写一个软件,特别是界面相关的,我们会使用以前已经编写好的窗口,或网上的开源模块.举一个简单的例子来说,如果你要编写一个视频播放器,关于视频的播放窗口,就用不着用DUI来实现,我们完全可以使用网上的开源库,嵌入一个播放的WND即可(当然有的库也支持回调的方式,用户可以在自己的窗口中将回调出来的图片进行自由绘制). 我们需要在窗口大小改变时,即时地改变播放窗口的大

Duilib学习三 响应按钮

1 #pragma once 2 #include <UIlib.h> 3 using namespace DuiLib; 4 5 #ifdef _DEBUG 6 # ifdef _UNICODE 7 # pragma comment(lib, "DuiLib_ud.lib") 8 # else 9 # pragma comment(lib, "DuiLib_d.lib") 10 # endif 11 #else 12 # ifdef _UNICODE

Duilib教程-控件练习

一.控件消息的响应. 在HelloDuilib例子中,程序不能退出,在这里,我将添加一个关闭按钮,当点击它时,调用PostQuitMessage进行退出. 首先在界面的右上角添加一个关闭按钮,并取名为“btnClose”. 然后在 CHelloDuilibWnd 中重载 WindowImplBase::Notify (); 代码如下: void CHelloDuilibWnd::Notify( TNotifyUI& msg ) { if (msg.sType == DUI_MSGTYPE_CLI