From f271cc61e8480c6ac319e5d3ea7e845a6bd0ed1c Mon Sep 17 00:00:00 2001 From: Tomay Date: Sat, 1 Dec 2018 14:06:22 +0100 Subject: [PATCH] Fall back on default margins if the theme doesn't provide them ::GetThemeMargins() may fail if the custom theme being currently used doesn't implement the required functionality, so initialize MARGINS with some reasonable values before calling it, if only in order to avoid using uninitialized (and so wildly wrong) margin values in this case. Closes https://github.com/wxWidgets/wxWidgets/pull/1036 Closes #18278. --- src/msw/anybutton.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index c4c4d11f53..c2daf84c7d 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -524,7 +524,9 @@ void wxAnyButton::AdjustForBitmapSize(wxSize &size) const { wxUxThemeHandle theme(const_cast(this), L"BUTTON"); - MARGINS margins; + // Initialize margins with the default values (at least under + // Windows 7) in case GetThemeMargins() fails. + MARGINS margins = {3, 3, 3, 3}; ::GetThemeMargins(theme, NULL, BP_PUSHBUTTON, PBS_NORMAL, @@ -1148,8 +1150,9 @@ void DrawXPBackground(wxAnyButton *button, HDC hdc, RECT& rectBtn, UINT state) ::DrawThemeBackground(theme, hdc, BP_PUSHBUTTON, iState, &rectBtn, NULL); - // calculate content area margins - MARGINS margins; + // calculate content area margins, using the defaults in case we fail to + // retrieve the current theme margins + MARGINS margins = {3, 3, 3, 3}; ::GetThemeMargins(theme, hdc, BP_PUSHBUTTON, iState, TMT_CONTENTMARGINS, &rectBtn, &margins); ::InflateRect(&rectBtn, -margins.cxLeftWidth, -margins.cyTopHeight);