+extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
+{
+ HWND hwnd = (HWND)hWnd;
+
+ // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
+ // by code in msw/radiobox.cpp), for all the others we just search up the
+ // window hierarchy
+ wxWindow *win = (wxWindow *)NULL;
+ if ( hwnd )
+ {
+ win = wxFindWinFromHandle((WXHWND)hwnd);
+ if ( !win )
+ {
+ // the radiobox pointer is stored in GWL_USERDATA only under Win32
+#ifdef __WIN32__
+ // native radiobuttons return DLGC_RADIOBUTTON here and for any
+ // wxWindow class which overrides WM_GETDLGCODE processing to
+ // do it as well, win would be already non NULL
+ if ( ::SendMessage((HWND)hwnd, WM_GETDLGCODE,
+ 0, 0) & DLGC_RADIOBUTTON )
+ {
+ win = (wxWindow *)::GetWindowLong(hwnd, GWL_USERDATA);
+ }
+ else
+#endif // Win32
+ {
+ // hwnd is not a wxWindow, try its parent next below
+ hwnd = ::GetParent(hwnd);
+ }
+ }
+ //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
+ }
+
+ while ( hwnd && !win )
+ {
+ win = wxFindWinFromHandle((WXHWND)hwnd);
+ hwnd = ::GetParent(hwnd);
+ }
+
+ return win;
+}
+