diff --git a/include/wx/msw/menu.h b/include/wx/msw/menu.h index 5f4c9f1853..0a56d318de 100644 --- a/include/wx/msw/menu.h +++ b/include/wx/msw/menu.h @@ -67,6 +67,9 @@ public: // menu handle and will delete it when this object is destroyed. static wxMenu *MSWNewFromHMENU(WXHMENU hMenu) { return new wxMenu(hMenu); } + // 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; } // implementation only from now on // ------------------------------- diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index cb6102110a..acc9e48867 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -352,7 +352,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()) ) {