对话中有一个picture控件,用来显示一bmp,我想实现picture控件的拖动,但由于picture属于CStatic,只有BN_CLICKED消息,所以我从CStatic中派生了CMyStatic类来响应WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE消息,消息处理函数中实现:
void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
m_mousedown=TRUE;
CStatic::OnLButtonDown(nFlags, point);
}void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default    if(m_mousedown)
    {
CPoint point1;
point1=point;
ClientToScreen(&point1);
CRect rect1;
GetWindowRect(&rect1);
MoveWindow(point1.x,point1.y,rect1.Width(),rect1.Height());      }    CStatic::OnMouseMove(nFlags, point);
}
void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
         m_mousedown=FALSE;
CStatic::OnLButtonUp(nFlags, point);
}
我的问题是:
MoveWindow(point1.x,point1.y,rect1.Width(),rect1.Height())移动picture控件的位置总也不对,感觉每次移动距离过大,超出了鼠标移动距离好几倍,不知是何原因?请大虾帮忙!

解决方案 »

  1.   

    可能是logical coordinates 和 device coordinates之间的关系。
    你试试DPtoLP、LPtoDP
      

  2.   

    是不是要将这个对象的模式设置为MM_TEXT以象素移动???
      

  3.   

    你试试:   if(nFlags|MK_LBUTTON) //m_mousedown可以不要
        {
    CRect rect1;
    GetWindowRect(&rect1);
    ClientToScreen(&rect1); //<<--映射到屏幕
             m_pParentWnd->ScreenToClient(&rect1);// <<-- 映射到父窗口
    MoveWindow(&rect1);
        }
     
      

  4.   

    MoveWindow()改变窗口的位置和尺寸,若被移动窗口是顶层窗口,此位置和尺寸坐标是相对于屏幕左上角的坐标;若被移动窗口是子窗口,此位置和尺寸坐标是相对于父窗口左上角的坐标;