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. Setting menu item as checked

Setting menu item as checked

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
7 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.
  • J Offline
    J Offline
    Jay Hova
    wrote on last edited by
    #1

    Hi, I would like to have my menu item to have a check next to it as it displays windows. In other words, if the window that is launched by the menu item is not NULL, then I want a check next to it and if not i don't want the check to be next to the menu item. I can get it to be unchecked at app start up and checked when the menu item is first selected. I am having problems on how to uncheck the item when the window is closed. Any help you be appreciated. Thanks in advance.

    T B 2 Replies Last reply
    0
    • J Jay Hova

      Hi, I would like to have my menu item to have a check next to it as it displays windows. In other words, if the window that is launched by the menu item is not NULL, then I want a check next to it and if not i don't want the check to be next to the menu item. I can get it to be unchecked at app start up and checked when the menu item is first selected. I am having problems on how to uncheck the item when the window is closed. Any help you be appreciated. Thanks in advance.

      T Offline
      T Offline
      Toni78
      wrote on last edited by
      #2

      Did you have a look at FAQ [^]? When you handle UPDATE_COMMAND_UI in the class wizard you do something like this:

      void CMyApp::OnUpdateMyMenuItem(CCmdUI* pCmdUI)
      {
      // I could be wrong about the syntax but you can
      // check it out on your own.
      pCmdUI->Enable( DisplayedWindow == NULL );
      pCmdUI->SetCheck( DisplayedWindow == NULL );
      }

      // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

      J 1 Reply Last reply
      0
      • T Toni78

        Did you have a look at FAQ [^]? When you handle UPDATE_COMMAND_UI in the class wizard you do something like this:

        void CMyApp::OnUpdateMyMenuItem(CCmdUI* pCmdUI)
        {
        // I could be wrong about the syntax but you can
        // check it out on your own.
        pCmdUI->Enable( DisplayedWindow == NULL );
        pCmdUI->SetCheck( DisplayedWindow == NULL );
        }

        // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

        J Offline
        J Offline
        Jay Hova
        wrote on last edited by
        #3

        Hi, I don't want to disable the window, i just want the menu item to be unchecked whenever the window is closed. I got it to be checked, just can't get it unchecked. I searched but didn't find what i was looking for. thanks for the suggestion. Any more help would be appreciated.

        T 1 Reply Last reply
        0
        • J Jay Hova

          Hi, I would like to have my menu item to have a check next to it as it displays windows. In other words, if the window that is launched by the menu item is not NULL, then I want a check next to it and if not i don't want the check to be next to the menu item. I can get it to be unchecked at app start up and checked when the menu item is first selected. I am having problems on how to uncheck the item when the window is closed. Any help you be appreciated. Thanks in advance.

          B Offline
          B Offline
          Beer26
          wrote on last edited by
          #4

          Here is the answer you were probably looking for, but until now, didn't get in the new dialog class add this function. Now the new dialogs will control that menu item in it's parent. void MyClass::checkmymenuitem(int checked) { CMenu* pMainMenu = GetParent()->GetMenu(); CMenu *submenu = pMainMenu->GetSubMenu(1); // replace 1 by the horizontal menu position UINT g = submenu->GetMenuItemID(3); // replace 3 by the actual vertical item position CString mnustr; submenu->GetMenuString(3, mnustr, MF_BYPOSITION); // replace 3 by the actual vertical item position // you can optionally change mnustr to a text here if (checked) submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_CHECKED, g, mnustr); else submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, g, mnustr); } in initdialog checkmymenuitem(true); then in onclose checkmymenuitem(false);

          J 1 Reply Last reply
          0
          • J Jay Hova

            Hi, I don't want to disable the window, i just want the menu item to be unchecked whenever the window is closed. I got it to be checked, just can't get it unchecked. I searched but didn't find what i was looking for. thanks for the suggestion. Any more help would be appreciated.

            T Offline
            T Offline
            Toni78
            wrote on last edited by
            #5

            Jay Hova wrote: I got it to be checked, just can't get it unchecked. This is what pCmdUI->SetCheck( DisplayedWindow == NULL ) does (actually it should be DisplayedWindow != NULL). When you close your window have a pointer that refers to that window and set it to NULL. DisplayedWindow supposedly is a pointer that you should declare and initialized when you create the window and destory it when you close the window. In my code if DisplayedWindow != NULL evaluates to true then the menu item will be checked, otherwise it will be unchecked. Check CCmdUI class. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

            1 Reply Last reply
            0
            • B Beer26

              Here is the answer you were probably looking for, but until now, didn't get in the new dialog class add this function. Now the new dialogs will control that menu item in it's parent. void MyClass::checkmymenuitem(int checked) { CMenu* pMainMenu = GetParent()->GetMenu(); CMenu *submenu = pMainMenu->GetSubMenu(1); // replace 1 by the horizontal menu position UINT g = submenu->GetMenuItemID(3); // replace 3 by the actual vertical item position CString mnustr; submenu->GetMenuString(3, mnustr, MF_BYPOSITION); // replace 3 by the actual vertical item position // you can optionally change mnustr to a text here if (checked) submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_CHECKED, g, mnustr); else submenu->ModifyMenu(3, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, g, mnustr); } in initdialog checkmymenuitem(true); then in onclose checkmymenuitem(false);

              J Offline
              J Offline
              Jay Hova
              wrote on last edited by
              #6

              Beer26, This is what i want...but I still have a problem. I put in the code that you gave me and it works fine at start up and the first time that the menu item is selected. But if i close the window and the select the menu item again, it doesn't update with a check mark the second time. Am i doing something wrong or is there something else that needs to be done? Thanks for the help btw, i really appreciate it

              B 1 Reply Last reply
              0
              • J Jay Hova

                Beer26, This is what i want...but I still have a problem. I put in the code that you gave me and it works fine at start up and the first time that the menu item is selected. But if i close the window and the select the menu item again, it doesn't update with a check mark the second time. Am i doing something wrong or is there something else that needs to be done? Thanks for the help btw, i really appreciate it

                B Offline
                B Offline
                Beer26
                wrote on last edited by
                #7

                "it doesn't update with a check mark the second time." It should, you could make sure that the 2nd windows's parent is the window with the menu, and you could put some code in there to make sure the pointers aren't NULL;

                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