From 63432e5ef5d387047e18f301577475d1df4ef503 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Mon, 21 Jan 2019 11:45:40 +0100 Subject: [PATCH] Fix wxShowEvent not being received for maximized frames on MSW Send wxEVT_SHOW explicitly when showing a maximized TLW under MSW as the system doesn't send WM_SHOW in this case (as documented in the MSDN and also confirmed by testing). Closes https://github.com/wxWidgets/wxWidgets/pull/1153 --- src/msw/toplevel.cpp | 10 ++++++++++ tests/toplevel/toplevel.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index b883d9d8f9..d7c4cfc79f 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -605,6 +605,16 @@ bool wxTopLevelWindowMSW::Show(bool show) DoShowWindow(nShowCmd); + if ( show && nShowCmd == SW_MAXIMIZE ) + { + // We don't receive WM_SHOWWINDOW when shown in the maximized state, + // cf. https://docs.microsoft.com/en-us/windows/desktop/winmsg/wm-showwindow + // and so we have to issue the event ourselves in this case. + wxShowEvent event(GetId(), true); + event.SetEventObject(this); + AddPendingEvent(event); + } + return true; } diff --git a/tests/toplevel/toplevel.cpp b/tests/toplevel/toplevel.cpp index 5e62a1b05c..6cd816eaf4 100644 --- a/tests/toplevel/toplevel.cpp +++ b/tests/toplevel/toplevel.cpp @@ -24,6 +24,8 @@ #include "wx/toplevel.h" #endif // WX_PRECOMP +#include "testableframe.h" + static void TopLevelWindowShowTest(wxTopLevelWindow* tlw) { CHECK(!tlw->IsShown()); @@ -75,3 +77,30 @@ TEST_CASE("wxTopLevel::Show", "[tlw][show]") frame->Destroy(); } } + +// Check that we receive the expected event when showing the TLW. +TEST_CASE("wxTopLevel::ShowEvent", "[tlw][show][event]") +{ + wxFrame* const frame = new wxFrame(NULL, wxID_ANY, "Maximized frame"); + + EventCounter countShow(frame, wxEVT_SHOW); + + frame->Maximize(); + frame->Show(); + + // Wait for the event to be received for the maximum of 2 seconds. + int showCount = 0; + for ( int i = 0; i < 40; i++ ) + { + wxYield(); + + showCount = countShow.GetCount(); + + if ( showCount ) + break; + + wxMilliSleep(50); + } + + CHECK( showCount == 1 ); +}