如何拖动用duilib创建出来的窗口
4个回答
2015-03-11 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数: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);
}
[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);
}
展开全部
在基类中做默认的控件拖动判断, 在子类中做特殊控件判断, 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?
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
展开全部
直接打开拖动。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询