鼠标捕获

void CCaptureMouseView::OnLButtonDown(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 SetCapture();//捕捉鼠标
 CString s;
 s.Format("用户摁下鼠标左键的位置:X=%d,Y=%d",point.x,point.y);
 CClientDC dc(this);          //获得DC
 dc.TextOut(30,40,s);      //输出文本
 CView::OnLButtonDown(nFlags, point);
}

 

void CCaptureMouseView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 ReleaseCapture();//释放鼠标 
 CClientDC dc(this);          //获得DC
 dc.TextOut(30,40,"释放了鼠标,此时可以响应客户窗口以外的鼠标命令!");      //输出文本

 CView::OnLButtonDblClk(nFlags, point);
}

void CCaptureMouseView::OnLButtonUp(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 CString s;
 s.Format("用户松开鼠标左键的位置:X=%d,Y=%d",point.x,point.y);
 CClientDC dc(this);          //获得DC
 dc.TextOut(30,80,s);      //输出文本
 
 CView::OnLButtonUp(nFlags, point);
}

你可能感兴趣的:(鼠标)