Fix fatal bug in wxGetWindowFromHWND() for radio buttons.
wxGetWindowFromHWND() could crash if it was called for a HWND of a radio button which was not created by wxWidgets because it blindly dereferenced the user data associated with the button expecting it to be a pointer to wxRadioBox and crashed if it was something different. And this actually happened when using the standard Windows printing dialog which can contain radio buttons which obviously used their user data field for their own purposes. Fix this by maintaining a global hash map with radio buttons HWNDs as keys and radio boxes as values. This ensures that we can always safely check whether the given HWND is a radio button in one of our radio boxes or not. Also change wxSpinCtrl which already did something similar in a different way (using an array instead or a more efficient hash map) for consistency. Closes #12083. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65957 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -90,6 +90,10 @@
|
||||
#include "wx/caret.h"
|
||||
#endif // wxUSE_CARET
|
||||
|
||||
#if wxUSE_RADIOBOX
|
||||
#include "wx/radiobox.h"
|
||||
#endif // wxUSE_RADIOBOX
|
||||
|
||||
#if wxUSE_SPINCTRL
|
||||
#include "wx/spinctrl.h"
|
||||
#endif // wxUSE_SPINCTRL
|
||||
@@ -6547,7 +6551,7 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
|
||||
// do it as well, win would be already non NULL
|
||||
if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON )
|
||||
{
|
||||
win = (wxWindow *)wxGetWindowUserData(hwnd);
|
||||
win = wxRadioBox::GetFromRadioButtonHWND(hwnd);
|
||||
}
|
||||
//else: it's a wxRadioButton, not a radiobutton from wxRadioBox
|
||||
#endif // wxUSE_RADIOBOX
|
||||
|
Reference in New Issue
Block a user