我要做的是单击鼠标就把鼠标指针控制在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);
}
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);
}
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);
----------------------------------
我试了,还是控制的是整个显示器的区域,不是我那程序的窗口.
是不是要先获得我那程序窗口的指针呀?
{
// 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);
}
这句是什么作用呢?
为什么有的程序,有ScreenToClient(&rect);的语句,我删了也可以照样运行呢?谢谢
{
// 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);
}
{
// 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);
}