From 6f888df4740b9014f4a3eeaba5aac64e84358071 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 24 Apr 2021 14:56:49 +0100 Subject: [PATCH] Restore button size calculation when not using manifest in wxMSW This fixes regression introduced in de10f054c4 (Improve calculating wxButton best size under wxMSW, 2021-04-08) which didn't check whether BCM_GETIDEALSIZE succeeded -- as we must do, because in some situations (when using very old systems or not using a manifest even under newer ones), it does indeed fail. --- src/msw/anybutton.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index edac3edad1..9310e33f1a 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -580,17 +580,23 @@ wxSize wxAnyButton::DoGetBestSize() const wxSize size; - // BCM_GETIDEALSIZE works properly only it there is a text label in the button. - if ( !IsOwnerDrawn() && ShowsLabel() ) + // The preferred way is to use BCM_GETIDEALSIZE, but it only works properly + // if there is a text label in the button and can't be used under old + // systems or without a manifest. + if ( !IsOwnerDrawn() && ShowsLabel() && + wxGetWinVersion() >= wxWinVersion_Vista ) { SIZE idealSize = { 0, 0 }; - ::SendMessage(GetHwnd(), BCM_GETIDEALSIZE, 0, (LPARAM)&idealSize); - size.Set(idealSize.cx, idealSize.cy); + if ( ::SendMessage(GetHwnd(), BCM_GETIDEALSIZE, 0, (LPARAM)&idealSize) ) + size.Set(idealSize.cx, idealSize.cy); - if ( m_imageData ) - AdjustForBitmapMargins(size); + if ( m_imageData ) + AdjustForBitmapMargins(size); } - else + + // If we failed to set the size using BCM_GETIDEALSIZE above, determine it + // ourselves. + if ( size == wxSize() ) { // Account for the text part if we have it. if ( ShowsLabel() )