MFC打开了一幅图像,如何用鼠标拖动该图像?

解决方案 »

  1.   

    响应WM_MOUSEMOVE消息,如果左键按下,根据鼠标位置重绘图像
      

  2.   

    图形放 CStatic 中 时 是:void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    static CPoint ptLast;
    //
    if(MK_LBUTTON==nFlags)
    {
    CRect rc;
    GetWindowRect(&rc);
    ScreenToClient(&rc);
    MapWindowPoints(GetParent(),&rc);
    MoveWindow(rc.left+(point.x-ptLast.x), rc.top+(point.y-ptLast.y), rc.Width(), rc.Height());
    }
    else
    {
    ptLast=point;
    CStatic::OnMouseMove(nFlags, point);
    }
    Invalidate();
    }
      

  3.   

    if(MK_LBUTTON==nFlags)
    如果 左键 按 下
     else
        {
            ptLast=point; 保存 当前 位置