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
This commit is contained in:
Vojtech Kral
2019-01-21 11:45:40 +01:00
committed by Vadim Zeitlin
parent f10939862a
commit 63432e5ef5
2 changed files with 39 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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 );
}