捕获鼠标经过的所有窗口
一般要用到以下函数:
SetCapture() ;
ReleaseCapture() ;
ClientToScreen() ;
WindowFromPoint() ;
以SDI为例。
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture() ;
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ReleaseCapture() ;
CView::OnRButtonDown(nFlags, point);
}
void CMyView::OnMouseMove(nFlags, point);
{
CWnd *pWnd ;
if(GetCapture() == NULL)
return ;
ClientToScreen(&point) ;
pWnd = WindowFromPoint(point) ;
if(pWnd == this)
return ;
//将所得窗口句柄显示出来,可放在OnDraw中处理
CString s ;
s.Format("%p", pWnd->GetSafeHwnd()) ;
CDC *pDC = GetDC() ;
pDC->TextOut(0,0,s) ;
ReleaseDC(pDC) ;
}
//按住mouse左键MoveMouse可显示mouse经过的窗口句柄,RButtonDown释放mouse