<Window size="280,400" caption="22,22,22,50" roundcorner="5,5" defaultfontcolor="#FFFFFBF0" caption="0,0,0,-1">
caption="0,0,0,-1” 在windows的布局中,加入这个属性即可,别做其他的。
网上说那些要重写 OnNcHitTest函数的,虽然能拖动 但是所有的鼠标点击事件没了。
LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt;
RECT rcClient;
RECT rcCaption;
rcCaption = m_pm.GetCaptionRect();
GetClientRect(m_pm.GetPaintWindow(), &rcClient);
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
::ScreenToClient(m_pm.GetPaintWindow(), &pt);
//xml中设置bottom为-1时,整个窗口区域都可以拖动
if (-1 == rcCaption.bottom)
{
rcCaption.bottom = rcClient.bottom;
}
if ((pt.x >= rcClient.left)
&& (pt.x < rcClient.right)
&& (pt.y >= rcCaption.top)
&& (pt.y < rcCaption.bottom))
{
return HTCAPTION;
}
return __super::OnNcHitTest(uMsg, wParam, lParam, bHandled);
}