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. i can disable menu item but cannot gray it!!!!!!!!

i can disable menu item but cannot gray it!!!!!!!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 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.
  • C Offline
    C Offline
    caykahve
    wrote on last edited by
    #1

    Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks... // The menu looks like: // File Settings // Item1 Item2 // Item3

    void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
    {
    if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
    {
    UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
    if(pCmdUI->m_pMenu!=NULL)
    pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
    }
    pCmdUI->Enable(Item3Enable);
    }

    void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
    {
    if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
    {
    UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;

    CMenu \*hMenu;
    hMenu = AfxGetMainWnd()->GetMenu();		
    CMenu \*sub;
    sub = hMenu->GetSubMenu(1);
    sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
    

    }
    pCmdUI->Enable(Item3Enable);
    }

    B J C 3 Replies Last reply
    0
    • C caykahve

      Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks... // The menu looks like: // File Settings // Item1 Item2 // Item3

      void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
      {
      if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
      {
      UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
      if(pCmdUI->m_pMenu!=NULL)
      pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
      }
      pCmdUI->Enable(Item3Enable);
      }

      void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
      {
      if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
      {
      UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;

      CMenu \*hMenu;
      hMenu = AfxGetMainWnd()->GetMenu();		
      CMenu \*sub;
      sub = hMenu->GetSubMenu(1);
      sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
      

      }
      pCmdUI->Enable(Item3Enable);
      }

      B Offline
      B Offline
      Brian Delahunty
      wrote on last edited by
      #2

      what is Item3Enable??? I presume it's a bool that you've set somewhere else in the program.... and you're passing that into pCmdUI->Enable() at the end of each handler but you are not changing the true/false value of Item3Enable so you seem to be enabling the menu item at the end of each handler. Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
      http://www.briandela.com/pictures Now with a pictures section :-D
      http://www.briandela.com/rss/newsrss.xml RSS Feed

      C 1 Reply Last reply
      0
      • B Brian Delahunty

        what is Item3Enable??? I presume it's a bool that you've set somewhere else in the program.... and you're passing that into pCmdUI->Enable() at the end of each handler but you are not changing the true/false value of Item3Enable so you seem to be enabling the menu item at the end of each handler. Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
        http://www.briandela.com/pictures Now with a pictures section :-D
        http://www.briandela.com/rss/newsrss.xml RSS Feed

        C Offline
        C Offline
        caykahve
        wrote on last edited by
        #3

        Yes, I set the bool variable Item3Enable to true somewhere else when I want to have ID_SETTINGS_ITEM3 enabled, and to false when I want to have ID_SETTINGS_ITEM3 disabled.

        1 Reply Last reply
        0
        • C caykahve

          Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks... // The menu looks like: // File Settings // Item1 Item2 // Item3

          void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
          {
          if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
          {
          UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
          if(pCmdUI->m_pMenu!=NULL)
          pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
          }
          pCmdUI->Enable(Item3Enable);
          }

          void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
          {
          if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
          {
          UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;

          CMenu \*hMenu;
          hMenu = AfxGetMainWnd()->GetMenu();		
          CMenu \*sub;
          sub = hMenu->GetSubMenu(1);
          sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
          

          }
          pCmdUI->Enable(Item3Enable);
          }

          J Offline
          J Offline
          Jaime Stuardo
          wrote on last edited by
          #4

          Just do: pCmdUI->Enable(FALSE); when pCmdUI->m_nID is ID_SETTINGS_ITEM3 that is, simply you can do: pCmdUI->Enable(pCmdUI->m_nID != ID_SETTINGS_ITEM3); Jaime

          C 1 Reply Last reply
          0
          • J Jaime Stuardo

            Just do: pCmdUI->Enable(FALSE); when pCmdUI->m_nID is ID_SETTINGS_ITEM3 that is, simply you can do: pCmdUI->Enable(pCmdUI->m_nID != ID_SETTINGS_ITEM3); Jaime

            C Offline
            C Offline
            caykahve
            wrote on last edited by
            #5

            I have already set it to false, item 3 becomes disabled, but not gray!! besides I do not want to have it always disabled, therefore I have put the variable Item3Enable, which I set to true or false in another function outside. I must be able to point to item 3 somehow and disable it but pCmdUI->m_pMenu is always NULL. I cannot manage to disable item 3 with GetMenu() and GetSubMenu() either, although I know it is possible to check and uncheck a menu item on a COMMAND message mapped to it using GetMenu() and GetsubMenu(). Does not anyone know why this doesn't work?

            J 1 Reply Last reply
            0
            • C caykahve

              I have already set it to false, item 3 becomes disabled, but not gray!! besides I do not want to have it always disabled, therefore I have put the variable Item3Enable, which I set to true or false in another function outside. I must be able to point to item 3 somehow and disable it but pCmdUI->m_pMenu is always NULL. I cannot manage to disable item 3 with GetMenu() and GetSubMenu() either, although I know it is possible to check and uncheck a menu item on a COMMAND message mapped to it using GetMenu() and GetsubMenu(). Does not anyone know why this doesn't work?

              J Offline
              J Offline
              Jaime Stuardo
              wrote on last edited by
              #6

              Have you tried to put pCmdUI->Enable(FALSE) as the only instruction in the update handler? If that way the menu option is grayed, the problem is the condition you have. By the way, if that update handler is called only for item 3, you don't need that verification. Finally, I tell you that I use my own application to place pCmdUI->Enable(FALSE) for a specific menu item and it worked (disabled and grayed) so the problem may be in your condition. Jaime

              C 1 Reply Last reply
              0
              • J Jaime Stuardo

                Have you tried to put pCmdUI->Enable(FALSE) as the only instruction in the update handler? If that way the menu option is grayed, the problem is the condition you have. By the way, if that update handler is called only for item 3, you don't need that verification. Finally, I tell you that I use my own application to place pCmdUI->Enable(FALSE) for a specific menu item and it worked (disabled and grayed) so the problem may be in your condition. Jaime

                C Offline
                C Offline
                caykahve
                wrote on last edited by
                #7

                Yes, it was only one line pCmdUI->Enable(true/false) before I encluntered the problem of non-grayed disabling. I put the other code to be able to gray it. actually I found it in some documents on internet, but none of the examples I saw directly match the situation I have. You're right about the verification being unncessary, i did that to be sure.

                J 1 Reply Last reply
                0
                • C caykahve

                  Yes, it was only one line pCmdUI->Enable(true/false) before I encluntered the problem of non-grayed disabling. I put the other code to be able to gray it. actually I found it in some documents on internet, but none of the examples I saw directly match the situation I have. You're right about the verification being unncessary, i did that to be sure.

                  J Offline
                  J Offline
                  Jaime Stuardo
                  wrote on last edited by
                  #8

                  I can guess that you have in other part of your program a code to "ungray" the item. Check that. Other fact to check. Are other menu items grayed that you see grayed? maybe is only a display problem. Jaime

                  1 Reply Last reply
                  0
                  • C caykahve

                    Hi, I have a dialog based app, want to disable and gray a sub menu item and I cannot gray it. I tried to find a solution to this problem but could not. Neither of the following work. :mad: What happens is I see Item 3 in black, press it, and nothing happens. I could have done it by modifying the code that is called when Item 3 is pressed. Why would I bother with OnUpdate? What's the use of it? I got no idea! :confused: I will be very happy if someone can help me. Thanks... // The menu looks like: // File Settings // Item1 Item2 // Item3

                    void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
                    {
                    if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
                    {
                    UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;
                    if(pCmdUI->m_pMenu!=NULL)
                    pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex /*ID_SETTINGS_ITEM3*/, MF_BYPOSITION|fGray);
                    }
                    pCmdUI->Enable(Item3Enable);
                    }

                    void CMyDlg::OnUpdateSettingsItem3(CCmdUI* pCmdUI)
                    {
                    if (pCmdUI->m_nID==ID_SETTINGS_ITEM3)
                    {
                    UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED;

                    CMenu \*hMenu;
                    hMenu = AfxGetMainWnd()->GetMenu();		
                    CMenu \*sub;
                    sub = hMenu->GetSubMenu(1);
                    sub->EnableMenuItem(ID\_SETTINGS\_ITEM3, MF\_BYPOSITION|fGray); }
                    

                    }
                    pCmdUI->Enable(Item3Enable);
                    }

                    C Offline
                    C Offline
                    caykahve
                    wrote on last edited by
                    #9

                    I solved the problem and I'm very happy for that!! :-D ok.. forget the function mapped to UPDATE_COMMAND_UI - delete it! Somewhere outside do this to switch between enabled and disabled menu items - nothing else //enable-disable switch // Item3Enable is the bool value to decide if it will be enabled or disabled Item3Enable = !Item3Enable; UINT fGray = Item3Enable ? 0 : MF_GRAYED|MF_DISABLED; CMenu *hMenu; hMenu = GetMenu(); CMenu *sub; sub = hMenu->GetSubMenu(1); sub->EnableMenuItem(ID_SETTINGS_ITEM3, MF_BYCOMMAND|fGray);

                    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