CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: SetCheck(0)

  1. #1
    Guest

    SetCheck(0)

    I was wondering how to set a checkmark by a menu item, and toggle between on/off each time the user clicked the menu item. I can do it with pop-up menus with EnableCheckItem( MF_CHECKED ), but with the dialog menu i can't do that?

    thanks



  2. #2
    Join Date
    May 1999
    Posts
    38

    Re: SetCheck(0)

    Hi,

    I had no such problem, I over written the virtual function for the MENU, (the ON_COMMAND, of the menu item), and did this inside that function:

    GetMenu()->GetSubMenu(0)->CheckMenuItem(0, MF_CHECKED | MF_BYPOSITION );

    This caused the first item to be marked as CHECKED (notice the GetSubMenu(0) and the MF_BYPOSITION (and of course the 0), you will need to adjust this acordingly).




  3. #3
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: SetCheck(0)

    In ClassWizard, select the menu item and add a function for the Message UPDATE_COMMAND_UI then add the code that's bold below:

    void CYourDoc::OnUpdateMenuItem(CCmdUI* pCmdUI)
    {
    pCmdUI->SetCheck(m_bFlag);
    }

    Depending on if m_bFlag is TRUE or FALSE, the menu item will be checked... so in the function that's executed when you use this menu item:
    void CYourDoc::OnMenuItem()
    {
    m_bFlag = !m_bFlag;

    // Do something...
    }

    Rail

    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    [email protected]
    http://home.earthlink.net/~railro/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured