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. Menu items grayed out?

Menu items grayed out?

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

    All items are grayed out, why?

    void CMyFrameWnd::OnRButtonUp(UINT nFlags, CPoint p)
    {
    CMenu menu;
    menu.CreatePopupMenu();
    menu.AppendMenu( MF_STRING | MF_ENABLED , 700 , "Zoom All" );
    menu.AppendMenu( MF_STRING | MF_ENABLED , 701 , "Properties" );
    ClientToScreen(&p);
    menu.TrackPopupMenu(TPM_CENTERALIGN,p.x,p.y,this,NULL);
    CFrameWnd::OnRButtonUp(nFlags, point);
    }

    D 1 Reply Last reply
    0
    • J Jesper Knudsen

      All items are grayed out, why?

      void CMyFrameWnd::OnRButtonUp(UINT nFlags, CPoint p)
      {
      CMenu menu;
      menu.CreatePopupMenu();
      menu.AppendMenu( MF_STRING | MF_ENABLED , 700 , "Zoom All" );
      menu.AppendMenu( MF_STRING | MF_ENABLED , 701 , "Properties" );
      ClientToScreen(&p);
      menu.TrackPopupMenu(TPM_CENTERALIGN,p.x,p.y,this,NULL);
      CFrameWnd::OnRButtonUp(nFlags, point);
      }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Do you have a handler function for menu items 700 and 701?


      "Take only what you need and leave the land as you found it." - Native American Proverb

      J 1 Reply Last reply
      0
      • D David Crow

        Do you have a handler function for menu items 700 and 701?


        "Take only what you need and leave the land as you found it." - Native American Proverb

        J Offline
        J Offline
        Jesper Knudsen
        wrote on last edited by
        #3

        No I am overriding OnCommand() For CWnd's this seems to be enough - maybe for CFrameWnd's it's not enough?

        D 1 Reply Last reply
        0
        • J Jesper Knudsen

          No I am overriding OnCommand() For CWnd's this seems to be enough - maybe for CFrameWnd's it's not enough?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          MFC's framework will disable menu items for which a handler has not been provided. There is no way for it to know that you are handling menu item requests from within OnCommand().


          "Take only what you need and leave the land as you found it." - Native American Proverb

          J 2 Replies Last reply
          0
          • D David Crow

            MFC's framework will disable menu items for which a handler has not been provided. There is no way for it to know that you are handling menu item requests from within OnCommand().


            "Take only what you need and leave the land as you found it." - Native American Proverb

            J Offline
            J Offline
            Jesper Knudsen
            wrote on last edited by
            #5

            So I shouldn't override OnCommand(), instead I should create a handler? ON_COMMAND_RANGE( 700 , 701 , OnMenuCommand ) afx_msg void OnMenuCommand ( UINT nID ) I just wonder - why is OnCommand() virtual then?

            J D 2 Replies Last reply
            0
            • J Jesper Knudsen

              So I shouldn't override OnCommand(), instead I should create a handler? ON_COMMAND_RANGE( 700 , 701 , OnMenuCommand ) afx_msg void OnMenuCommand ( UINT nID ) I just wonder - why is OnCommand() virtual then?

              J Offline
              J Offline
              John M Drescher
              wrote on last edited by
              #6

              You can add onupdatecmdui handlers for each id and then use oncmommand, I do this a lot. John

              1 Reply Last reply
              0
              • D David Crow

                MFC's framework will disable menu items for which a handler has not been provided. There is no way for it to know that you are handling menu item requests from within OnCommand().


                "Take only what you need and leave the land as you found it." - Native American Proverb

                J Offline
                J Offline
                Jesper Knudsen
                wrote on last edited by
                #7

                Thank you for your help, it works with the handler - still I wonder, still I wonder.. :)

                D 1 Reply Last reply
                0
                • J Jesper Knudsen

                  So I shouldn't override OnCommand(), instead I should create a handler? ON_COMMAND_RANGE( 700 , 701 , OnMenuCommand ) afx_msg void OnMenuCommand ( UINT nID ) I just wonder - why is OnCommand() virtual then?

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Jesper Knudsen wrote:

                  So I shouldn't override OnCommand(), instead I should create a handler?

                  That's how I would proceed.

                  Jesper Knudsen wrote:

                  I just wonder - why is OnCommand() virtual then?

                  It has its purpose. My most recent use of it was on a property sheet. I needed to handle the clicking of the OK button.


                  "Take only what you need and leave the land as you found it." - Native American Proverb

                  1 Reply Last reply
                  0
                  • J Jesper Knudsen

                    Thank you for your help, it works with the handler - still I wonder, still I wonder.. :)

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    MFC's message routing does take a little bit to get used to. The framework looks for an entry in the BEGIN_MESSAGE_MAP() method for both menu items and toolbar buttons. If one is not found, it does not enable that item or button. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfcnotes_tn021.asp[^]


                    "Take only what you need and leave the land as you found it." - Native American Proverb

                    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