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. MFC Menu Graying.

MFC Menu Graying.

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionworkspace
6 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.
  • K Offline
    K Offline
    kiasu_kid
    wrote on last edited by
    #1

    Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.

    T J J 3 Replies Last reply
    0
    • K kiasu_kid

      Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.

      T Offline
      T Offline
      Terry ONolley
      wrote on last edited by
      #2

      Try using the method EnableMenuItem() with nEnable set to MF_GRAYED. From the docs: ============================= CMenu::EnableMenuItem UINT EnableMenuItem( UINT nIDEnableItem, UINT nEnable ); MF_GRAYED Disables the menu item so that it cannot be selected and dims it. ============================= For this to work, you'll need to use CMenu classes for your menus and not just resource menus. If you don't want to use CMenu, then you can gray menus by using the SDK call EnableMenuItem: ============================= The EnableMenuItem function enables, disables, or grays the specified menu item. BOOL EnableMenuItem( HMENU hMenu, // handle to menu UINT uIDEnableItem, // menu item to enable, disable, or gray UINT uEnable // menu item flags ); =============================


      Have you answered an MTQ? Check out the stats!

      K 1 Reply Last reply
      0
      • T Terry ONolley

        Try using the method EnableMenuItem() with nEnable set to MF_GRAYED. From the docs: ============================= CMenu::EnableMenuItem UINT EnableMenuItem( UINT nIDEnableItem, UINT nEnable ); MF_GRAYED Disables the menu item so that it cannot be selected and dims it. ============================= For this to work, you'll need to use CMenu classes for your menus and not just resource menus. If you don't want to use CMenu, then you can gray menus by using the SDK call EnableMenuItem: ============================= The EnableMenuItem function enables, disables, or grays the specified menu item. BOOL EnableMenuItem( HMENU hMenu, // handle to menu UINT uIDEnableItem, // menu item to enable, disable, or gray UINT uEnable // menu item flags ); =============================


        Have you answered an MTQ? Check out the stats!

        K Offline
        K Offline
        kiasu_kid
        wrote on last edited by
        #3

        Thanx. I'll try it out.

        1 Reply Last reply
        0
        • K kiasu_kid

          Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          This is an unusual question, because MFC atomaticaly grays submenus until the use specifies a handler or explicitly says not to gray it. The question why is the menue item grayed is far more commond (a good thing). One of the great things about using MFC class wizard it that you do not need to know the details (although you should). When you bring up the class wizard it gives you a chance to specify a handler to use when you select an item (menu/button/etc..) as well as wheather it is enable or not. INTP

          K 1 Reply Last reply
          0
          • J John R Shaw

            This is an unusual question, because MFC atomaticaly grays submenus until the use specifies a handler or explicitly says not to gray it. The question why is the menue item grayed is far more commond (a good thing). One of the great things about using MFC class wizard it that you do not need to know the details (although you should). When you bring up the class wizard it gives you a chance to specify a handler to use when you select an item (menu/button/etc..) as well as wheather it is enable or not. INTP

            K Offline
            K Offline
            kiasu_kid
            wrote on last edited by
            #5

            What i try to say is that how do i gray a particular submenu when i press a button for instance. I know that in the properties, you could gray the submenu. But what i need is to gray the submenu during runtime.

            1 Reply Last reply
            0
            • K kiasu_kid

              Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.

              J Offline
              J Offline
              jbarton
              wrote on last edited by
              #6

              The normal MFC way of enabling/disabling menu items during runtime is to implement the UPDATE_COMMAND_UI handler for the item. To do this, use the class wizard to add an UPDATE_COMMAND_UI message handler for the particular menu item that you want to handle: - On the "Message Maps" page, select the object id of the menu item that you want to control - select the UPDATE_COMMAND_UI in the Messages window. - Click on the "Add Function" button to add a handler for it. - Click on the "Edit Code" button to goto the code for the newly added handler. In the handler code, you can control whether the menu item is enabled or disabled as follows: - To enable the menu item, call pCmdUI->Enable( TRUE ); - To disable the menu item, call pCmdUI->Enable( FALSE );

              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