如何拖动用duilib创建出来的窗口

 我来答
huanglenzhi
2015-03-11 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517201
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
在基类中做默认的控件拖动判断, 在子类中做特殊控件判断, e.g. 点击某个静态控件时,要弹出一个对话框.

[cpp] view
plaincopyprint?

class CMainDlg : public CXmlWnd
class CMainDlg : public CXmlWnd

基类:

[cpp] view
plaincopyprint?

virtual LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

ate:

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

private:
BOOL IsInStaticControl(CControlUI * pControl);

[cpp] view
plaincopyprint?

LRESULT CXmlWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)

{

POINT pt;

RECT rcClient;

RECT rcCaption;

CControlUI * pControl = NULL;

rcCaption = m_PaintManager.GetCaptionRect();

GetClientRect(m_PaintManager.GetPaintWindow(), &rcClient);

pt.x = GET_X_LPARAM(lParam);

pt.y = GET_Y_LPARAM(lParam);

::ScreenToClient(m_PaintManager.GetPaintWindow(), &pt);

if (-1 == rcCaption.bottom) ///< xml中描述bottom为-1时,整个窗口区域都可以拖动

{

rcCaption.bottom = rcClient.bottom;

}

if ((pt.x >= rcClient.left)

&& (pt.x < rcClient.right)

&& (pt.y >= rcCaption.top)

&& (pt.y < rcCaption.bottom))

{

pControl = m_PaintManager.FindControl(pt);

if (IsInStaticControl(pControl))

{

return HTCAPTION;

}

}

return __super::OnNcHitTest(uMsg, wParam, lParam, bHandled);

}

BOOL CXmlWnd::IsInStaticControl(CControlUI * pControl)

{

CDuiString strClassName;

std::vector<CDuiString> vctStaticName;

std::vector<CDuiString>::iterator it;

if (NULL == pControl)

return FALSE;

strClassName = pControl->GetClass();

strClassName.MakeLower();

vctStaticName.push_back(L"controlui");

vctStaticName.push_back(L"textui");

vctStaticName.push_back(L"labelui");

vctStaticName.push_back(L"containerui");

vctStaticName.push_back(L"horizontallayoutui");

vctStaticName.push_back(L"verticallayoutui");

vctStaticName.push_back(L"tablayoutui");

vctStaticName.push_back(L"childlayoutui");

vctStaticName.push_back(L"dialoglayoutui");

it = std::find(vctStaticName.begin(), vctStaticName.end(), strClassName);

return (it != vctStaticName.end());

}
LRESULT CXmlWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt;
RECT rcClient;
RECT rcCaption;
CControlUI * pControl = NULL;

rcCaption = m_PaintManager.GetCaptionRect();
GetClientRect(m_PaintManager.GetPaintWindow(), &rcClient);
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
::ScreenToClient(m_PaintManager.GetPaintWindow(), &pt);

if (-1 == rcCaption.bottom) ///< xml中描述bottom为-1时,整个窗口区域都可以拖动
{
rcCaption.bottom = rcClient.bottom;
}

if ((pt.x >= rcClient.left)
&& (pt.x < rcClient.right)
&& (pt.y >= rcCaption.top)
&& (pt.y < rcCaption.bottom))
{
pControl = m_PaintManager.FindControl(pt);
if (IsInStaticControl(pControl))
{
return HTCAPTION;
}
}

return __super::OnNcHitTest(uMsg, wParam, lParam, bHandled);
}

BOOL CXmlWnd::IsInStaticControl(CControlUI * pControl)
{
CDuiString strClassName;
std::vector<CDuiString> vctStaticName;
std::vector<CDuiString>::iterator it;

if (NULL == pControl)
return FALSE;

strClassName = pControl->GetClass();
strClassName.MakeLower();
vctStaticName.push_back(L"controlui");
vctStaticName.push_back(L"textui");
vctStaticName.push_back(L"labelui");
vctStaticName.push_back(L"containerui");
vctStaticName.push_back(L"horizontallayoutui");
vctStaticName.push_back(L"verticallayoutui");
vctStaticName.push_back(L"tablayoutui");
vctStaticName.push_back(L"childlayoutui");
vctStaticName.push_back(L"dialoglayoutui");

it = std::find(vctStaticName.begin(), vctStaticName.end(), strClassName);
return (it != vctStaticName.end());
}

子类

[cpp] view
plaincopyprint?

LRESULT CMainDlg::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)

{

POINT pt;

CDuiString str;

CControlUI * pControl = NULL;

pt.x = GET_X_LPARAM(lParam);

pt.y = GET_Y_LPARAM(lParam);

::ScreenToClient(m_PaintManager.GetPaintWindow(), &pt);

pControl = m_PaintManager.FindControl(pt);

str = pControl->GetName();

/// 如果是要处理点击的界面元素是静态控件, 要单独处理, 返回 HTCLIENT

if ((str == ELEMENT_MAIN_DLG_CTRL_XX)

|| (str == ELEMENT_MAIN_DLG_CTRL_YY))

{

return HTCLIENT; ///< 要处理的控件不能拖动,可以处理点击

}

return __super::OnNcHitTest(uMsg, wParam, lParam, bHandled);

}
shihoumacili
高粉答主

2015-12-18 · 每个回答都超有意思的
知道大有可为答主
回答量:1.1万
采纳率:87%
帮助的人:497万
展开全部

选中xml文件,在属性对话框中更改caption的四个值即可,如图:

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
范冰冰_求追
推荐于2016-08-06 · 超过29用户采纳过TA的回答
知道答主
回答量:128
采纳率:0%
帮助的人:42.8万
展开全部
在基类中做默认的控件拖动判断, 在子类中做特殊控件判断, e.g. 点击某个静态控件时,要弹出一个对话框.

[cpp] view
plaincopyprint?

class CMainDlg : public CXmlWnd
class CMainDlg : public CXmlWnd

基类:

[cpp] view
plaincopyprint?

virtual LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

ate:

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

private:
BOOL IsInStaticControl(CControlUI * pControl);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2015-03-10
展开全部
直接打开拖动。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式