// ----------------------------------------------------------------------------
// the (popup) menu title has this special id
// ----------------------------------------------------------------------------
// the (popup) menu title has this special id
- if ( !::DestroyMenu(GetHmenu()) )
+ // 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() )
// id is the numeric id for normal menu items and HMENU for submenus as
// required by ::AppendMenu() API
// id is the numeric id for normal menu items and HMENU for submenus as
// required by ::AppendMenu() API
wxMenu *submenu = pItem->GetSubMenu();
if ( submenu != NULL ) {
wxASSERT_MSG( submenu->GetHMenu(), wxT("invalid submenu") );
submenu->SetParent(this);
wxMenu *submenu = pItem->GetSubMenu();
if ( submenu != NULL ) {
wxASSERT_MSG( submenu->GetHMenu(), wxT("invalid submenu") );
submenu->SetParent(this);
{
// visually select the menu title
SetDefaultMenuItem(GetHmenu(), id);
{
// visually select the menu title
SetDefaultMenuItem(GetHmenu(), id);
if ( !label.empty() )
{
if ( !::InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING,
if ( !label.empty() )
{
if ( !::InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING,
!::InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) )
{
wxLogLastError(wxT("InsertMenu"));
!::InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) )
{
wxLogLastError(wxT("InsertMenu"));
#else
if ( !ModifyMenu(hMenu, 0u,
MF_BYPOSITION | MF_STRING,
#else
if ( !ModifyMenu(hMenu, 0u,
MF_BYPOSITION | MF_STRING,
for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
{
if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
{
if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION);
if ( flagsOld == 0xFFFFFFFF )
{
UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION);
if ( flagsOld == 0xFFFFFFFF )
{
info.fType = MFT_STRING;
info.cch = label.length();
info.dwTypeData = wx_const_cast(wxChar *, label.wx_str());
info.fType = MFT_STRING;
info.cch = label.length();
info.dwTypeData = wx_const_cast(wxChar *, label.wx_str());
- if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) )
+ if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, &info) )
if ( !::InsertMenu(GetHmenu(), (UINT)mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING,
if ( !::InsertMenu(GetHmenu(), (UINT)mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING,
#else
if ( !::InsertMenu(GetHmenu(), mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING,
#else
if ( !::InsertMenu(GetHmenu(), mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING,