From bc6eba6043d5b7e5688c93bda8bbf10d4c007302 Mon Sep 17 00:00:00 2001 From: Troels Knakkergaard Date: Sat, 5 Mar 2016 04:04:20 +0100 Subject: [PATCH] Reset the parent MDI menu after destroying MDI child in wxMSW This is necessary to avoid menu corruption in case the child creation fails. Closes #17315. --- docs/changes.txt | 1 + src/msw/mdi.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index a31c66cc36..4ab6f1dd5c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -66,6 +66,7 @@ All: wxMSW: - Fix crash when using wxCHMHelpController() in 64 bit builds (Xlord2). +- Fix MDI menu display after failure to create a child frame (troelsk). wxOSX: diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index 0793cd2ad1..514e4eedfe 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -910,7 +910,9 @@ wxMDIChildFrame::~wxMDIChildFrame() if ( !m_hWnd ) return; - GetMDIParent()->RemoveMDIChild(this); + wxMDIParentFrame * const parent = GetMDIParent(); + + parent->RemoveMDIChild(this); // will be destroyed by DestroyChildren() but reset them before calling it // to avoid using dangling pointers if a callback comes in the meanwhile @@ -925,6 +927,12 @@ wxMDIChildFrame::~wxMDIChildFrame() MDIRemoveWindowMenu(NULL, m_hMenu); + // MDIRemoveWindowMenu() doesn't update the MDI menu when called with NULL + // window, so do it ourselves. + MDISetMenu(parent->GetClientWindow(), + (HMENU)parent->MSWGetActiveMenu(), + GetMDIWindowMenu(parent)); + MSWDestroyWindow(); }