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. Enabling/Disabling a CMFCRibbonButton

Enabling/Disabling a CMFCRibbonButton

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 2 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.
  • Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #1

    How does one arbitrarily enable or disable a button on the Ribbon bar? The OnUpdateCommand handler only allows you to specify a change in response to a button-click. But I want to enable or disable the button from elsewhere in the program.

    The difficult we do right away... ...the impossible takes slightly longer.

    L 1 Reply Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      How does one arbitrarily enable or disable a button on the Ribbon bar? The OnUpdateCommand handler only allows you to specify a change in response to a button-click. But I want to enable or disable the button from elsewhere in the program.

      The difficult we do right away... ...the impossible takes slightly longer.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I think you want the ON_UPDATE_COMMAND_UI macro[^].

      Richard Andrew x64R 1 Reply Last reply
      0
      • L Lost User

        I think you want the ON_UPDATE_COMMAND_UI macro[^].

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #3

        Thanks for your response. That macro allows me to add an OnUpdateCommandUI handler which gets called right after the button is clicked. But how does it allow me to do something like ribbonButton.Enabled(FALSE); NOT in response to a button click?

        The difficult we do right away... ...the impossible takes slightly longer.

        L 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          Thanks for your response. That macro allows me to add an OnUpdateCommandUI handler which gets called right after the button is clicked. But how does it allow me to do something like ribbonButton.Enabled(FALSE); NOT in response to a button click?

          The difficult we do right away... ...the impossible takes slightly longer.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I guess it's just a matter of creating a function that can enable or disable the button, something like:

          void EnableButton(CMFCRibbonButton& ribbonButton, bool bEnable)
          {
          ribbonButton.Enable(bEnable);
          }

          or better still, a function that enables/disables all the buttons based on a set of rules ...

          void EnableButtons(int nRule, bool bEnable)
          {
          switch (rule)
          {
          case 1:
          ribbonButton1.Enable(bEnable);
          ribbonButton2.Enable(bEnable);
          break;
          case 2:
          ribbonButton1.Enable(bEnable);
          ribbonButton6.Enable(bEnable);
          ribbonButton7.Enable(bEnable);
          break;
          // ... etc
          }
          }

          You then call this function from elsewhere in response to some arbitrary decision of your own.

          Richard Andrew x64R 1 Reply Last reply
          0
          • L Lost User

            I guess it's just a matter of creating a function that can enable or disable the button, something like:

            void EnableButton(CMFCRibbonButton& ribbonButton, bool bEnable)
            {
            ribbonButton.Enable(bEnable);
            }

            or better still, a function that enables/disables all the buttons based on a set of rules ...

            void EnableButtons(int nRule, bool bEnable)
            {
            switch (rule)
            {
            case 1:
            ribbonButton1.Enable(bEnable);
            ribbonButton2.Enable(bEnable);
            break;
            case 2:
            ribbonButton1.Enable(bEnable);
            ribbonButton6.Enable(bEnable);
            ribbonButton7.Enable(bEnable);
            break;
            // ... etc
            }
            }

            You then call this function from elsewhere in response to some arbitrary decision of your own.

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            Now you've hit upon the exact problem: The CMFCRibbonButton does not have an "Enable" method, or any method like it, hence my dilemma. Thanks again for your time.

            The difficult we do right away... ...the impossible takes slightly longer.

            L 1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              Now you've hit upon the exact problem: The CMFCRibbonButton does not have an "Enable" method, or any method like it, hence my dilemma. Thanks again for your time.

              The difficult we do right away... ...the impossible takes slightly longer.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              That seems strange, since the base class has an IsDisabled() function. I also noticed in Word2010 that some buttons are disabled so it must be possible. The SO question at http://stackoverflow.com/questions/502640/disable-enable-ribbon-buttons-for-mfc-feature-pack[^] suggests that it uses the normal MFC macros as I suggested earlier.

              Richard Andrew x64R 1 Reply Last reply
              0
              • L Lost User

                That seems strange, since the base class has an IsDisabled() function. I also noticed in Word2010 that some buttons are disabled so it must be possible. The SO question at http://stackoverflow.com/questions/502640/disable-enable-ribbon-buttons-for-mfc-feature-pack[^] suggests that it uses the normal MFC macros as I suggested earlier.

                Richard Andrew x64R Offline
                Richard Andrew x64R Offline
                Richard Andrew x64
                wrote on last edited by
                #7

                I hear what you're saying, but that IsDisabled() property is read-only. And the SO question you link to says basically what we already know about the MFC macros. That's why I can't figure this out. :sigh:

                The difficult we do right away... ...the impossible takes slightly longer.

                L 1 Reply Last reply
                0
                • Richard Andrew x64R Richard Andrew x64

                  I hear what you're saying, but that IsDisabled() property is read-only. And the SO question you link to says basically what we already know about the MFC macros. That's why I can't figure this out. :sigh:

                  The difficult we do right away... ...the impossible takes slightly longer.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Sorry nor can I. But given what I said about Word and the SO question, it must be possible. Unfortunately it is too many years since I used MFC in anger so I can't even try a few things. I wonder where all the CodeProject MFC experts are?

                  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