首页 > 代码库 > Duilib改进窗口拖动,使整个窗口都能拖动(转载)

Duilib改进窗口拖动,使整个窗口都能拖动(转载)

转载:http://www.cnblogs.com/XiHua/articles/3490490.html

转载:http://blog.csdn.net/lostspeed/article/details/19275249

 

这种方法不修改Duilib库的源码,需要的话直接在你自己的窗口类中添加两个方法实现,不需要的话,还使用原来的方法。

 

MyWnd

.h文件

1 virtual LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);  
2    
3 BOOL IsInStaticControl(CControlUI * pControl); 

.cpp文件

加入头文件 

1 #include <algorithm>
 1 LRESULT MyWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 2 {
 3     POINT           pt;  
 4     RECT            rcClient;  
 5     RECT            rcCaption;  
 6     CControlUI *    pControl = NULL;  
 7 
 8     rcCaption = m_PaintManager.GetCaptionRect();  
 9     GetClientRect(m_PaintManager.GetPaintWindow(), &rcClient);  
10     pt.x = GET_X_LPARAM(lParam);  
11     pt.y = GET_Y_LPARAM(lParam);  
12     ::ScreenToClient(m_PaintManager.GetPaintWindow(), &pt);  
13 
14     if (-1 == rcCaption.bottom) ///< xml中描述bottom为-1时,整个窗口区域都可以拖动  
15     {  
16         rcCaption.bottom = rcClient.bottom;  
17     }  
18 
19     if ((pt.x >= rcClient.left)  
20         && (pt.x < rcClient.right)  
21         && (pt.y >= rcCaption.top)   
22         && (pt.y < rcCaption.bottom))   
23     {  
24         pControl = m_PaintManager.FindControl(pt);  
25         if (IsInStaticControl(pControl))  
26         {  
27             return HTCAPTION;  
28         }  
29     }  
30 
31     return __super::OnNcHitTest(uMsg, wParam, lParam, bHandled); 
32 }
33 
34 BOOL MyWnd::IsInStaticControl(CControlUI * pControl)
35 {
36     CDuiString strClassName;  
37     std::vector<CDuiString> vctStaticName;  
38     std::vector<CDuiString>::iterator it;  
39 
40     if (NULL == pControl)  
41         return FALSE;  
42 
43     strClassName = pControl->GetClassName();  
44     strClassName.MakeLower();  
45     vctStaticName.push_back(L"controlui");  
46     vctStaticName.push_back(L"textui");  
47     vctStaticName.push_back(L"labelui");  
48     vctStaticName.push_back(L"containerui");  
49     vctStaticName.push_back(L"horizontallayoutui");  
50     vctStaticName.push_back(L"verticallayoutui");  
51     vctStaticName.push_back(L"tablayoutui");  
52     vctStaticName.push_back(L"childlayoutui");  
53     vctStaticName.push_back(L"dialoglayoutui");  
54 
55     it = std::find(vctStaticName.begin(), vctStaticName.end(), strClassName);  
56     return (it != vctStaticName.end());  
57 }

最后在窗口xml中指定caption="0,0,0,-1",不管窗口大小如何变,都可以整个窗口拖动啦~

效果图:

技术分享

Duilib改进窗口拖动,使整个窗口都能拖动(转载)