none
checking menu items RRS feed

Answers

  • The MFC way is not to manipulate the menu directly. There is a so called OnCommand Handler and OnUpdateCommand handelr technique.

    In the OnUpdate Handler of your command just use pCmdUI->SetCheck(m_bMyState);

    Sunday, February 19, 2006 5:52 PM
    Moderator
  • Thanks guys for all the help.  I tried both the ways you suggested but neither one worked, but they did get me going in the right direction and I found that this way did work:

    CWnd::OnContextMenu()...

    CMenu menu;
    menu.LoadMenu(IDR_POPUP_MENU);

    CMenu *popupMenu = menu.GetSubMenu(0);
    popupMenu->CheckMenuItem(ID_DOCKED, MF_BYCOMMAND | (isDocked ? MF_CHECKED : MF_UNCHECKED));


    Thanks again for all the help.
    Sunday, February 19, 2006 8:07 PM

All replies

  • Lookup SetMenuItemInfo, MENUITEMINFO, and MFS_CHECKED on MSDN.

     Nathan87 wrote:
    How do you check a menu item in Visual Studio.Net 2003 using MFC?

    Sunday, February 19, 2006 12:18 PM
    Moderator
  • The MFC way is not to manipulate the menu directly. There is a so called OnCommand Handler and OnUpdateCommand handelr technique.

    In the OnUpdate Handler of your command just use pCmdUI->SetCheck(m_bMyState);

    Sunday, February 19, 2006 5:52 PM
    Moderator
  • Thanks guys for all the help.  I tried both the ways you suggested but neither one worked, but they did get me going in the right direction and I found that this way did work:

    CWnd::OnContextMenu()...

    CMenu menu;
    menu.LoadMenu(IDR_POPUP_MENU);

    CMenu *popupMenu = menu.GetSubMenu(0);
    popupMenu->CheckMenuItem(ID_DOCKED, MF_BYCOMMAND | (isDocked ? MF_CHECKED : MF_UNCHECKED));


    Thanks again for all the help.
    Sunday, February 19, 2006 8:07 PM
  • Martin Richter said:

    The MFC way is not to manipulate the menu directly. There is a so called OnCommand Handler and OnUpdateCommand handelr technique.

    In the OnUpdate Handler of your command just use pCmdUI->SetCheck(m_bMyState);


    I have tried this in Visual Studio 2008. I couldn’t get it to work.

    I tried setting it manually to 0, 1 or 2. But is still with no effect.

     

    Anyone have any ideas why? Does it matter if the handler is in the dlg files or the app files?

     

    Thanks in advance.

    Saturday, October 11, 2008 10:31 PM