MouseDown + SetCaptureMouseMove  里面移动,代码很好写,而且不受用户设置窗体移动方式的限制MouseUp + ReleaseCapture

解决方案 »

  1.   

    gameboy999(我心迷茫)
    能更详细解释一下用哪几个消息响应吗?
    是不是在mousedown中设setcapture;
    再在mouse中移动;
    然后再在mouseup中失去焦点;
    不过移动用什么实现呢?
    因为我和项目中的这样的对话框非常多,而且时间很紧,能不能给我初略地说一下要用到哪几个消息和函数?有胜感激!!
      

  2.   

    easy!!
    void CXXXDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default

    CDialog::OnLButtonDown(nFlags, point);
        PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
    }
      

  3.   

    对话框工作区中任意一点的托动afx_msg UINT OnNcHitTest(CPoint point);ON_WM_NCHITTEST()UINT CTest_01Dlg::OnNcHitTest(CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    return HTCAPTION;
    // return CDialog::OnNcHitTest(point);
    }这个更好实现移动。
      

  4.   

    void CWormholesDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    CDialog::OnLButtonDown(nFlags, point);
    PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
    //欺骗 Windows,发送拖动标题栏的消息,呵呵 
    }
      

  5.   

    PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));
    是没有办法实现的,它能实现拖动,但你见过拖动标题栏能拖动到-100,-100吗?它只能向下或向左右,但向屏幕上方越界就不可以了,不信你可以试试!!
    我用的也是这个方法,但没法解决向上边越出的,想寻求的解决方案
      

  6.   

    follow me:
    add 3 public varible into your dialog;int m_Oldx;
    int m_Oldy;
    bool m_IsMoving;
    CTestdlgDlg::CTestdlgDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTestdlgDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CTestdlgDlg)
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
        m_Oldx = 0;
        m_Oldy = 0;
        m_IsMoving = false;
    }
    void CTestdlgDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CPoint pt;
        GetCursorPos(&pt);
        m_Oldx = pt.x;
        m_Oldy = pt.y;
        m_IsMoving = true;
        SetCapture();
    CDialog::OnLButtonDown(nFlags, point);
    }
    void CTestdlgDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
        if(m_IsMoving)
        {
        CPoint pt;
            GetCursorPos(&pt);
            CRect rt;
            GetWindowRect(&rt);
            CRect rt1;
            rt1.left = pt.x - m_Oldx + rt.left ;
            rt1.top = pt.y - m_Oldy + rt.top ;
            rt1.right = rt1.left + rt.Width();
            rt1.bottom = rt1.top + rt.Height();
            MoveWindow(&rt1);
            m_Oldx = pt.x;
            m_Oldy = pt.y;
        }
        CDialog::OnMouseMove(nFlags, point);
    }void CTestdlgDlg::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
        m_IsMoving = false;
    ReleaseCapture();
    CDialog::OnLButtonUp(nFlags, point);
    }
      

  7.   

    gameboy999(我心迷茫)
    用你的实现了,谢谢,给分了