- if (m_hMenu)
- DestroyMenu((HMENU) m_hMenu);
- m_hMenu = 0;
-
- // Windows seems really bad on Menu de-allocation...
- // After many try, here is what I do: RemoveMenu() will ensure
- // that popup are "disconnected" from their parent; then call
- // delete method on each child (which in turn do a recursive job),
- // and finally, DestroyMenu()
- //
- // With that, BoundCheckers is happy, and no complaints...
-/*
- int N = 0 ;
- if (m_hMenu)
- N = GetMenuItemCount(m_hMenu);
- int i;
- for (i = N-1; i >= 0; i--)
- RemoveMenu(m_hMenu, i, MF_BYPOSITION);
-*/
-
- // How is deleting submenus in this loop any different from deleting
- // the submenus in the children list, via ~wxWindow ?
- // I'll reinstate this deletion for now and remove addition
- // from children list (which doesn't exist now)
- // Julian 1/3/97
- wxNode *node = m_menuItems.First();
- while (node)
- {
- wxMenuItem *item = (wxMenuItem *)node->Data();
-
- // Delete child menus.
- // Beware: they must not be appended to children list!!!
- // (because order of delete is significant)
- if (item->GetSubMenu())
- item->DeleteSubMenu();
-
- wxNode *next = node->Next();
- delete item;
- delete node;
- node = next;
- }
-/*
- if (m_hMenu)
- DestroyMenu(m_hMenu);
- m_hMenu = 0;
-*/
+ // 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 ( !::DestroyMenu(GetHmenu()) )
+ {
+ wxLogLastError(wxT("DestroyMenu"));
+ }
+ }
+
+#if wxUSE_ACCEL
+ // delete accels
+ WX_CLEAR_ARRAY(m_accels);
+#endif // wxUSE_ACCEL