獲取當前鼠標點處的窗口

void CGetWndDlg::OnMouseMove(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 CWnd *pWnd=WindowFromPoint(point);
 if(AfxIsValidAddress(pWnd,sizeof(CWnd)))
 {
  if(::IsChild(m_hWnd,pWnd->m_hWnd))
  {
   CString str;
   pWnd->GetWindowText(str);
   SetWindowText(str);
  }
 }

 CDialog::OnMouseMove(nFlags, point);
}

BOOL CGetWndDlg::PreTranslateMessage(MSG* pMsg)
{
 // TODO: Add your specialized code here and/or call the base class
 if(pMsg->message==WM_MOUSEMOVE)
 {
  CPoint point(LOWORD(pMsg->lParam),HIWORD(pMsg->lParam));
  ::ClientToScreen(pMsg->hwnd,&point);
  OnMouseMove(0,point);
 }

 return CDialog::PreTranslateMessage(pMsg);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章