一基于对话框程序,如何限制鼠标只能在此对话框内移动?急急急!!!

解决方案 »

  1.   

    GetCursorPos();得到光标的位置,如果在你的对话框外面,就把它拽回来用SetCursorPos();
    用法看一下MSDN就可以了
      

  2.   


    用Clipcursor(&rect)
    只能在这个矩形中用了。
    注意是屏幕坐标!!
      

  3.   

    如果是在对话框刚出现时就要将鼠标锁定在此对话框的区域里那又该怎么做呢?应该在那个事件中写代码呢?好像在INITDIALOG()不行,我该怎么做?
      

  4.   

    1、GetClienRect OR GetWindowRect获得对话框的区域,
       RECT DialogRect;
       GetClientRect(&DialogRect);
    2、限制鼠标:ClipCursor(&DialogRect);
    3、释放鼠标:ClipCursor(NULL);
      

  5.   

    windows核心编程中有类似的源码,可以去找来看。
      

  6.   

    void CTestDialogDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
    {
    CDialog::OnShowWindow(bShow, nStatus);

    // TODO: Add your message handler code here
    RECT rect;
    GetClientRect(&rect);
    ClientToScreen(&rect);
    ClipCursor(&rect);
    }
      

  7.   

    GetClientRect(&rect);
    ClientToScreen(&rect);
    ClipCursor(&rect);
      

  8.   

    还可在在C*Dlg::OnMouseMove()和::OnShowWindow()中进行判断。
    CRect rect;
    GetClientRect(&rect);
    POINT point;
    GetCursorPos(&point);
    if (rect.PtInRect(point))
    ....