Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to use CheckMenuItem()????????

How to use CheckMenuItem()????????

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi I would like to palce a check mark for menu item, if user clicks a menu item. I would like to do this from CMainFrm class.Can u please give me an idea? Thanks JP ;P

    F M 2 Replies Last reply
    0
    • A Anonymous

      Hi I would like to palce a check mark for menu item, if user clicks a menu item. I would like to do this from CMainFrm class.Can u please give me an idea? Thanks JP ;P

      F Offline
      F Offline
      Florin Ochiana
      wrote on last edited by
      #2

      You have to have a function that would execute the code when the users selects the menu item. Let's say it's ON_COMMAND(ID_YOURMENUITEM, TestFn) Maybe you want to use a global variable that will tell you the state of that item. bool testVar; void TestFn() { CMenu *m_MainMenu; // let's say you have your menu in m_MainMenu if (testVar) { testVar = false; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_UNCHECKED); } else { testVar = true; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_CHECKED); } } where n is the position of your item in the menu ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

      A 1 Reply Last reply
      0
      • F Florin Ochiana

        You have to have a function that would execute the code when the users selects the menu item. Let's say it's ON_COMMAND(ID_YOURMENUITEM, TestFn) Maybe you want to use a global variable that will tell you the state of that item. bool testVar; void TestFn() { CMenu *m_MainMenu; // let's say you have your menu in m_MainMenu if (testVar) { testVar = false; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_UNCHECKED); } else { testVar = true; m_MainMenu->GetSubMenu(1)->GetSubMenu(x)->CheckMenuItem(n, MF_BYPOSITION | MF_CHECKED); } } where n is the position of your item in the menu ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Hey In above example, m_MainMenu is unreferenced..so that code is not working. How to attach my Mainmeu to this? Thanks JP

        F 1 Reply Last reply
        0
        • A Anonymous

          Hey In above example, m_MainMenu is unreferenced..so that code is not working. How to attach my Mainmeu to this? Thanks JP

          F Offline
          F Offline
          Florin Ochiana
          wrote on last edited by
          #4

          I told you that m_MainMenu is your menu. You will have to replace it with your variable. If it's the apps menu then you have to do something like this m_MainMenu = GetMenu(); ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

          A 1 Reply Last reply
          0
          • A Anonymous

            Hi I would like to palce a check mark for menu item, if user clicks a menu item. I would like to do this from CMainFrm class.Can u please give me an idea? Thanks JP ;P

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            Use the ON_UPDATE_COMMAND_UI message if possible.

            ...
            ON_UPDATE_COMMAND_UI(IDM_YOUR_MENU_ITEM, OnUpdateYourMenuItem)
            ...

            void CMainFrm::OnUpdateYourMenuItem(CCmdUI* pCmdUI)
            {
            pCmdUI->SetCheck( IsMenuItemCheck() );
            }


            Maximilien Lincourt Your Head A Splode - Strong Bad

            1 Reply Last reply
            0
            • F Florin Ochiana

              I told you that m_MainMenu is your menu. You will have to replace it with your variable. If it's the apps menu then you have to do something like this m_MainMenu = GetMenu(); ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              Thank u very much!!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups