我要做的是单击鼠标就把鼠标指针控制在rect(0,0,100,100)中.但是我总是限制的是显示器的rect(0,0,100,100), 不是本窗口,怎么写这代码呀?
void CMyView::OnLButtonDown(UINT nFlags, CPoint point) 
{
          CRect rect;
         rect.setRect(0,0,100,100);
 CWnd* pWnd->GetWindowRect(&rect);
ClipCursor(&rect);
CView::OnLButtonDown(nFlags, point);
}

解决方案 »

  1.   

    CWnd* pWnd->GetWindowRect(&rect);这句去掉
      

  2.   

    另外,这样写:
         CRect rectold,rectnew;//(0,0,100,100);
     GetWindowRect(&rectold);
     CPoint mm;
     mm=rectold.TopLeft();
     rectnew=CRect(mm.x,mm.y,mm.x+100,mm.y+100); ClipCursor(&rectnew);

    CView::OnLButtonDown(nFlags, point);
      

  3.   

    pcitman(不缺分只缺钱) 
    ----------------------------------
    我试了,还是控制的是整个显示器的区域,不是我那程序的窗口.
    是不是要先获得我那程序窗口的指针呀?
      

  4.   

    void CMyView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect rect;
    GetClientRect(&rect);
    ClientToScreen(&rect);
    rect.right=rect.left+100;
    rect.bottom=rect.top+100;
    ClipCursor(&rect);
    CView::OnLButtonDown(nFlags, point);
    }
      

  5.   

    ClientToScreen(&rect);
    这句是什么作用呢?
    为什么有的程序,有ScreenToClient(&rect);的语句,我删了也可以照样运行呢?谢谢
      

  6.   

    如果没有这句的话,就只能控制屏幕上rect(0,0,100,100)了.
      

  7.   

    void CMyView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect rect;
    GetClientRect(&rect);//得到客户区的RECT,RECT的LEFT和TOP都是0
    ClientToScreen(&rect);//现在RECT的LEFT和TOP就是客户区的左上角在屏幕上的坐标了
    rect.right=rect.left+100;//
    rect.bottom=rect.top+100;//改变RECT的大小
    ClipCursor(&rect);
    CView::OnLButtonDown(nFlags, point);
    }
      

  8.   

    void CMyView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect rect;
    GetClientRect(&rect);//得到客户区的RECT,RECT的LEFT和TOP都是0
    ClientToScreen(&rect);//现在RECT的LEFT和TOP就是客户区的左上角在屏幕上的坐标了
    rect.right=rect.left+100;//
    rect.bottom=rect.top+100;//改变RECT的大小
    ClipCursor(&rect);
    CView::OnLButtonDown(nFlags, point);
    }