Enabling/Disabling a CMFCRibbonButton
-
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.
-
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.
-
I think you want the ON_UPDATE_COMMAND_UI macro[^].
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.
-
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.
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.
-
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.
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.
-
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.
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. -
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.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.
-
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.