#244 Assert in CCommandBarCtrl::OnInitMenuPopup

v1.0 (example)
Ivo Beltchev

If I have a default item in my menu and use CCommandBarCtrl::TrackPopupMenu, I get an assert in OnInitMenuPopup.
menuPopup.SetMenuItemInfo returns FALSE. It doesn't like the MF_DEFAULT item state. I'm guessing this state is not allowed to be set directly but one must use the SetMenuDefaultItem function. (like you can't just set WS_VISIBLE, but must call ShowWindow)

To repro this make a menu with a default item either set _WTL_CMDBAR_VISTA_MENUS to 0, or run with Classic theme. Otherwise this code is not used at all (m_bVistaMenus will be true).

My fix is to add:
mii.fState &= ~MF_DEFAULT;
right after this line:
if(!(mii.fType & MFT_OWNERDRAW)) // Not already an ownerdraw item

My tests show that (at least on Windows 7) removing the MF_DEFAULT state does not alter the default menu item, so it looks safe to remove that bit when calling SetMenuItemInfo. More testing is needed to figure out if that's true for all supported platforms.


    • assigned_to: nobody --> nenadstefanovic
    • status: open --> closed-wont-fix
    • Group: --> v1.0 (example)
  • This is very specific case, and you already have a workaround.

    In general, just use SetMenuDefaultItem() before calling TrackPopupMenu(). That works just fine (and using UpdateUI is not good for this).



Cancel   Add attachments