捕获鼠标

View Code
 1 void CKeyBoard_Mouse_MessageView::OnLButtonDown(UINT nFlags, CPoint point) 
2 {
3 SetCapture();//捕获鼠标,防止鼠标离开窗口区域捕获不到,无论鼠标在何位置,其产生的消息均发给捕获它的窗口
4 GetClipCursor(&oldrect);//获得原来鼠标的活动范围
5 CRect rect;
6 GetWindowRect(&rect);
7 ClipCursor(&rect);//将鼠标的移动限制在客户区
8 fDowned=true;
9 ptUp=ptDown=point;
10 CView::OnLButtonDown(nFlags, point);
11 }
12
13 void CKeyBoard_Mouse_MessageView::OnLButtonUp(UINT nFlags, CPoint point)
14 {
15 ReleaseCapture();//释放鼠标与SetCapture()配合使用
16 ClipCursor(&oldrect);//恢复鼠标的活动区域
17 if (fDowned)
18 {
19 ptUp=point;
20 DrawRec();
21 fDowned=false;
22 }
23 CView::OnLButtonUp(nFlags, point);
24 }

 

posted on 2011-12-29 20:05  Sunny_NUAA  阅读(250)  评论(0编辑  收藏  举报

导航