+wxWindowOS2* FindWindowForMouseEvent(
+ wxWindow* pWin
+, short* pnX
+, short* pnY
+)
+{
+ wxCHECK_MSG( pnX && pnY, pWin, _T("NULL pointer in FindWindowForMouseEvent") );
+ POINTL vPoint = { *pnX, *pnY };
+ HWND hWnd = GetHwndOf(pWin);
+ HWND hWndUnderMouse;
+
+ //
+ // First try to find a non transparent child: this allows us to send events
+ // to a static text which is inside a static box, for example
+ //
+
+ hWndUnderMouse = ::WinWindowFromPoint( hWnd
+ ,&vPoint
+ ,TRUE
+ );
+ if (!hWndUnderMouse || hWndUnderMouse == hWnd)
+ {
+ //
+ // Now try any child window at all
+ //
+ hWndUnderMouse = ::WinWindowFromPoint( HWND_DESKTOP
+ ,&vPoint
+ ,TRUE
+ );
+
+ }
+
+ //
+ // Check that we have a child window which is susceptible to receive mouse
+ // events: for this it must be shown and enabled
+ if ( hWndUnderMouse &&
+ hWndUnderMouse != hWnd &&
+ ::WinIsWindowVisible(hWndUnderMouse) &&
+ ::WinIsWindowEnabled(hWndUnderMouse))
+ {
+ wxWindow* pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse);
+ if (pWinUnderMouse)
+ {
+ // translate the mouse coords to the other window coords
+ pWin->ClientToScreen( (int*)pnX
+ ,(int*)pnY
+ );
+ pWinUnderMouse->ScreenToClient( (int*)pnX
+ ,(int*)pnY
+ );
+ pWin = pWinUnderMouse;
+ }
+ }
+ return pWin;
+} // end of FindWindowForMouseEvent
+