+// Windows doesn't send the mouse events to the static controls (which are
+// transparent in the sense that their WM_NCHITTEST handler returns
+// HTTRANSPARENT) at all but we want all controls to receive the mouse events
+// and so we manually check if we don't have a child window under mouse and if
+// we do, send the event to it instead of the window Windows had sent WM_XXX
+// to.
+//
+// Notice that this is not done for the mouse move events because this could
+// (would?) be too slow, but only for clicks which means that the static texts
+// still don't get move, enter nor leave events.
+static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y) //TW:REQ:Univ
+{
+ wxCHECK_MSG( x && y, win, _T("NULL pointer in FindWindowForMouseEvent") );
+
+ // 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
+ POINT pt = { *x, *y };
+ HWND hwnd = GetHwndOf(win),
+ hwndUnderMouse;
+
+#ifdef __WIN32__
+ hwndUnderMouse = ::ChildWindowFromPointEx
+ (
+ hwnd,
+ pt,
+ CWP_SKIPINVISIBLE |
+ CWP_SKIPDISABLED |
+ CWP_SKIPTRANSPARENT
+ );
+
+ if ( !hwndUnderMouse || hwndUnderMouse == hwnd )
+#endif // __WIN32__
+ {
+ // now try any child window at all
+ hwndUnderMouse = ::ChildWindowFromPoint(hwnd, pt);
+ }
+
+ // 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 &&
+ ::IsWindowVisible(hwndUnderMouse) &&
+ ::IsWindowEnabled(hwndUnderMouse) )
+ {
+ wxWindow *winUnderMouse = wxFindWinFromHandle((WXHWND)hwndUnderMouse);
+ if ( winUnderMouse )
+ {
+ // translate the mouse coords to the other window coords
+ win->ClientToScreen(x, y);
+ winUnderMouse->ScreenToClient(x, y);
+
+ win = winUnderMouse;
+ }
+ }
+
+ return win;
+}
+