直接使用如下就可以了,不用再使用继承。
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());
}
此外:我的caption设置的为caption="0,0,40,40" ,只能再标题栏中进行拖动窗口。
如果设置为caption="0,0,0,-1"时,整个界面任一点都可以拖动,且需要IsInStaticControl 中将所有需要响应消息的名字如button edit等进行添加上
参考:https://blog.csdn.net/lostspeed/article/details/19275249https://blog.csdn.net/lostspeed/article/details/19275249