- m_title = label ;
- if (m_hMenu)
- ModifyMenu((HMENU)m_hMenu, 0,
- MF_BYPOSITION | MF_STRING | MF_DISABLED,
- (UINT)-2, (const char *)m_title);
- else if (m_savehMenu)
- ModifyMenu((HMENU)m_savehMenu, 0,
- MF_BYPOSITION | MF_STRING | MF_DISABLED,
- (UINT)-2, (const char *)m_title);
+ bool hasNoTitle = m_title.IsEmpty();
+ m_title = label;
+
+ HMENU hMenu = (HMENU)((m_hMenu == 0) ? m_savehMenu : m_hMenu);
+
+ if ( hasNoTitle )
+ {
+ if ( !label.IsEmpty() )
+ {
+ if ( !InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING,
+ (unsigned)idMenuTitle, m_title) ||
+ !InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) )
+ {
+ wxLogLastError("InsertMenu");
+ }
+ }
+ }
+ else
+ {
+ if ( label.IsEmpty() )
+ {
+ // remove the title and the separator after it
+ if ( !RemoveMenu(hMenu, 0, MF_BYPOSITION) ||
+ !RemoveMenu(hMenu, 0, MF_BYPOSITION) )
+ {
+ wxLogLastError("RemoveMenu");
+ }
+ }
+ else
+ {
+ // modify the title
+ if ( !ModifyMenu(hMenu, 0u,
+ MF_BYPOSITION | MF_STRING,
+ (unsigned)idMenuTitle, m_title) )
+ {
+ wxLogLastError("ModifyMenu");
+ }
+ }
+ }
+
+ // TODO use SetMenuItemInfo(MFS_DEFAULT) to put it in bold face