子类化的static控件响应鼠标拖动讯息
子类化的static控件响应鼠标拖动消息
有一静态控件,已子类化,继承自CStatic,希望鼠标拖动的时候这个控件跟随一起拖动,
现在做出来不能跟随鼠标移动,每拖一次控件都变小一点,调试的时候看到拖动正常,直接运行就不对了,
控件总是跟不上鼠标。控件移动加上UpdateWindow()的时候发现每次都往原来的地方移回去。
调试的时候发现每次都先来OnMouseMove消息,
想不通哪里出了问题,请各位指教,本人分不多,请不要介意
------解决方案--------------------
void CMyStatic::OnMouseMove(UINT nFlags,CPoint point)
{
static CPoint ptLast=0;
if(nFlags==MK_LBUTTON)
{
CRect rc;
GetWindowRect(&rc);
ScreenToClient(&rc);
MapWindowPoints(GetParent(),&rc);
rc.offsetRect(point.x-ptLast.x,point.y-ptLast.y);
MoveWindow&rc);
}
else
{
ptLast=point;
}
// CStatic::OnMousMove(nFlags,point);
}
其他响应 都不要 !
有一静态控件,已子类化,继承自CStatic,希望鼠标拖动的时候这个控件跟随一起拖动,
现在做出来不能跟随鼠标移动,每拖一次控件都变小一点,调试的时候看到拖动正常,直接运行就不对了,
控件总是跟不上鼠标。控件移动加上UpdateWindow()的时候发现每次都往原来的地方移回去。
调试的时候发现每次都先来OnMouseMove消息,
想不通哪里出了问题,请各位指教,本人分不多,请不要介意
void CStaticVideo::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//获取当前控件大小
GetClientRect(&m_rect);
if (PtInRect(&m_rect, point))
{
ClientToScreen(&m_rect);
//窗口坐标转换成屏幕坐标
ClientToScreen(&point);
m_bMouseDown = TRUE;
m_NewPt = point;
SetCapture();
}
CStatic::OnLButtonDown(nFlags, point);
}
void CStaticVideo::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CPoint OldPt;
SIZE SubSize = {0};
if ((CPoint(0) != m_NewPt) && (m_NewPt != point) && (MK_LBUTTON == nFlags))
{
//窗口坐标转换成屏幕坐标
ClientToScreen(&point);
OldPt = m_NewPt;
m_NewPt = point;
SubSize.cx = m_NewPt.x - OldPt.x;
SubSize.cy = m_NewPt.y - OldPt.y;
CRect rect(m_rect);
rect.OffsetRect(SubSize);
ScreenToClient(&rect);
MoveWindow(rect);
//GetParent()->GetDlgItem(IDC_STATIC_BOARD)->UpdateWindow();
}
CStatic::OnMouseMove(nFlags, point);
}
void CStaticVideo::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CPoint OldPt;
if (TRUE == m_bMouseDown)
{
m_bMouseDown = FALSE;
ReleaseCapture();
}
CStatic::OnLButtonUp(nFlags, point);
}
------解决方案--------------------
void CMyStatic::OnMouseMove(UINT nFlags,CPoint point)
{
static CPoint ptLast=0;
if(nFlags==MK_LBUTTON)
{
CRect rc;
GetWindowRect(&rc);
ScreenToClient(&rc);
MapWindowPoints(GetParent(),&rc);
rc.offsetRect(point.x-ptLast.x,point.y-ptLast.y);
MoveWindow&rc);
}
else
{
ptLast=point;
}
// CStatic::OnMousMove(nFlags,point);
}
其他响应 都不要 !