From 5e4544356837ba9410f3ad983678fe98e9e111b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 18 Jun 2014 12:57:30 +0000 Subject: [PATCH] Add wxMenu::MSWDetachHMENU(). Make it possible to pass ownership of a wxMenu to win32. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@76725 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/menu.h | 5 +++++ src/msw/menu.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/menu.h b/include/wx/msw/menu.h index 5f4c9f1853..616b3044ad 100644 --- a/include/wx/msw/menu.h +++ b/include/wx/msw/menu.h @@ -67,6 +67,11 @@ public: // menu handle and will delete it when this object is destroyed. static wxMenu *MSWNewFromHMENU(WXHMENU hMenu) { return new wxMenu(hMenu); } +#if wxABI_VERSION >= 30002 + // Detaches HMENU so that it isn't deleted when this object is destroyed. + // Don't use this object after calling this method. + WXHMENU MSWDetachHMENU() { WXHMENU m = m_hMenu; m_hMenu = NULL; return m; } +#endif // implementation only from now on // ------------------------------- diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index cdc229ffe4..88682ec440 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -360,7 +360,7 @@ wxMenu::~wxMenu() // we should free Windows resources only if Windows doesn't do it for us // which happens if we're attached to a menubar or a submenu of another // menu - if ( !IsAttached() && !GetParent() ) + if ( m_hMenu && !IsAttached() && !GetParent() ) { if ( !::DestroyMenu(GetHmenu()) ) {