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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. EnableMenuItem() does not make menu item gray???

EnableMenuItem() does not make menu item gray???

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 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.
  • W Offline
    W Offline
    Wenrich
    wrote on last edited by
    #1

    Hi! I come across a strange thing: I try to gray a menu item, the codes as follow: CMenu *pMenu = GetMenu(); CMenu *pOP = pMenu->GetSubMenu(2); pOP->EnableMenuItem(ID_OP_START, MF_GRAYED | MF_BYCOMMAND); ****************************************************** The menu item with ID ID_OP_START is supposed to be grayed and GetMenuState() does return MF_GRAYED; but the item is actually not grayed and can still function as it does. Do I need to do something in order for this method to work? Thanks a lot!

    RaviBeeR 1 Reply Last reply
    0
    • W Wenrich

      Hi! I come across a strange thing: I try to gray a menu item, the codes as follow: CMenu *pMenu = GetMenu(); CMenu *pOP = pMenu->GetSubMenu(2); pOP->EnableMenuItem(ID_OP_START, MF_GRAYED | MF_BYCOMMAND); ****************************************************** The menu item with ID ID_OP_START is supposed to be grayed and GetMenuState() does return MF_GRAYED; but the item is actually not grayed and can still function as it does. Do I need to do something in order for this method to work? Thanks a lot!

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      Wenrich wrote: Do I need to do something in order for this method to work? What you're doing will work for a menu attached to a dialog in a dialog based app. However, if you're using MFC's doc/view framework (SDI/MDI), you need to put the enable/disable logic in the command's UpdateUI handler. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

      W 1 Reply Last reply
      0
      • RaviBeeR RaviBee

        Wenrich wrote: Do I need to do something in order for this method to work? What you're doing will work for a menu attached to a dialog in a dialog based app. However, if you're using MFC's doc/view framework (SDI/MDI), you need to put the enable/disable logic in the command's UpdateUI handler. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

        W Offline
        W Offline
        will1383
        wrote on last edited by
        #3

        Ravi Bhavnani wrote: What you're doing will work for a menu attached to a dialog in a dialog based app. However, if you're using MFC's doc/view framework (SDI/MDI), you need to put the enable/disable logic in the command's UpdateUI handler. This may be the case, but what if you need the change the menus from a different location other than in the UpdateUI handler? do you basically have to create a boolean to keep track of the state and then check it in the UpdateUI? Is this the only way? Thanks! Dan

        R RaviBeeR 2 Replies Last reply
        0
        • W will1383

          Ravi Bhavnani wrote: What you're doing will work for a menu attached to a dialog in a dialog based app. However, if you're using MFC's doc/view framework (SDI/MDI), you need to put the enable/disable logic in the command's UpdateUI handler. This may be the case, but what if you need the change the menus from a different location other than in the UpdateUI handler? do you basically have to create a boolean to keep track of the state and then check it in the UpdateUI? Is this the only way? Thanks! Dan

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          Another method would be to handle the WM_INITMENUPOPUP message and enable/disable the items in that handler. Roger Allen Sonork 100.10016 I have a terminal disease. Its called life!

          1 Reply Last reply
          0
          • W will1383

            Ravi Bhavnani wrote: What you're doing will work for a menu attached to a dialog in a dialog based app. However, if you're using MFC's doc/view framework (SDI/MDI), you need to put the enable/disable logic in the command's UpdateUI handler. This may be the case, but what if you need the change the menus from a different location other than in the UpdateUI handler? do you basically have to create a boolean to keep track of the state and then check it in the UpdateUI? Is this the only way? Thanks! Dan

            RaviBeeR Offline
            RaviBeeR Offline
            RaviBee
            wrote on last edited by
            #5

            groover4life wrote: create a boolean to keep track of the state and then check it in the UpdateUI? Yes, that follows the standard MVC model and would be the preferred way imho. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

            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