+ HWND hwnd = msg->hwnd;
+ wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hwnd);
+ wxWindow *wnd;
+
+ // this might happen if we're in a modeless dialog, or if a wx control has
+ // children which themselves were not created by wx (i.e. wxActiveX control children)
+ if ( !wndThis )
+ {
+ while ( hwnd && (::GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD ))
+ {
+ hwnd = ::GetParent(hwnd);
+
+ // If the control has a wx parent, break and give the parent a chance
+ // to process the window message
+ wndThis = wxGetWindowFromHWND((WXHWND)hwnd);
+ if (wndThis != NULL)
+ break;
+ }
+
+ if ( !wndThis )
+ {
+ // this may happen if the event occurred in a standard modeless dialog (the
+ // only example of which I know of is the find/replace dialog) - then call
+ // IsDialogMessage() to make TAB navigation in it work
+
+ // NOTE: IsDialogMessage() just eats all the messages (i.e. returns true for
+ // them) if we call it for the control itself
+ return hwnd && ::IsDialogMessage(hwnd, msg) != 0;
+ }
+ }
+
+ if ( !AllowProcessing(wndThis) )
+ {
+ // not a child of critical window, so we eat the event but take care to
+ // stop an endless stream of WM_PAINTs which would have resulted if we
+ // didn't validate the invalidated part of the window
+ if ( msg->message == WM_PAINT )
+ ::ValidateRect(hwnd, NULL);
+
+ return true;
+ }