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. checking and unchecking menu items

checking and unchecking menu items

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncement
4 Posts 3 Posters 0 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 all, I posted yesterday morning to try and get my menu item to be checked and unchecked as one of my dialogs is displayed via the menu item. I kinda need this to be accomplished soon, so i figured i could post it again because the original post is 5 or 6 pages into the message board. Beer26 was kind enough to help me with this solution.

    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);

    It works fine the first time the app is started(menu item unchecked), when the menu item is selected the first time (checked), and when the dialog is closed the first time(unchecked). BUT it doesn't update the menu at all after the first time it is selected and the dialog is closed. Can anyone help me figure this out PLEASE. I was originally trying to use a pointer to the dialog being displayed, but that led to the same result.

    M 1 Reply Last reply
    0
    • J Jay Hova

      Hi all, I posted yesterday morning to try and get my menu item to be checked and unchecked as one of my dialogs is displayed via the menu item. I kinda need this to be accomplished soon, so i figured i could post it again because the original post is 5 or 6 pages into the message board. Beer26 was kind enough to help me with this solution.

      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);

      It works fine the first time the app is started(menu item unchecked), when the menu item is selected the first time (checked), and when the dialog is closed the first time(unchecked). BUT it doesn't update the menu at all after the first time it is selected and the dialog is closed. Can anyone help me figure this out PLEASE. I was originally trying to use a pointer to the dialog being displayed, but that led to the same result.

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

      (haven't looked at the original question) can't you simply add a ON_UPDATE_COMMAND_UI command handler for the menu item ? and use :

      void MyClass::OnUpdateYourMenuItem( CCmdUI* pCmdUI )
      {
      pCmdUI ->SetCheck( IsYourDialogVisible() );
      }


      Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )

      B 1 Reply Last reply
      0
      • M Maximilien

        (haven't looked at the original question) can't you simply add a ON_UPDATE_COMMAND_UI command handler for the menu item ? and use :

        void MyClass::OnUpdateYourMenuItem( CCmdUI* pCmdUI )
        {
        pCmdUI ->SetCheck( IsYourDialogVisible() );
        }


        Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )

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

        I think he said his main app was dialog based, and as we all know the VC++6 generator has that bug that makes updating UI on menu items not work on dialog based apps. I forgot what the fix was for that but you can look it up on codeguru.com

        J 1 Reply Last reply
        0
        • B Beer26

          I think he said his main app was dialog based, and as we all know the VC++6 generator has that bug that makes updating UI on menu items not work on dialog based apps. I forgot what the fix was for that but you can look it up on codeguru.com

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

          Thank you for your help. I figured it out, and with your code it works great. The problem was that I just had to destroy the window when closing the window.

          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