I am using the MFC Feature Pack and I have some buttons on a ribbon bar, instances of CMFCRibbonButton. The problem is that I would like to enable and disable some of them in certain conditions, but at runtime. How can I do this? because there is no specific method for this...I heard that a solution would be to attach/detach the event handlers at runtime, but I do not know how...
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
When you create the
CMFCRibbonButton
object you have to specify the associated command ID (see the documentation for theCMFCRibbonButton
constructor here). Enabling and disabling of ribbon buttons is then done using the usual command update mechanism in MFC, using theCCmdUI
class.For example, if you have a ribbon button whose command ID is
ID_MYCOMMAND
and you want to handle this command in your application's view class, you should add these functions to the class:and implement them in the .cpp file:
You should also add
ON_COMMAND
andON_UPDATE_COMMAND_UI
entries to the message map for theCMyView
class:For more information on message maps in MFC, refer to TN006: Message Maps in MSDN.
I hope this helps!
ChrisN gave a pretty perfect answer. You can see an example of exactly how this is done by downloading the VS2008 Sample Pack from here, and opening the MSOffice2007Demo solution.
When running the sample, look at the "Thumbnails" checkbox in the View tab of the ribbon, it's disabled.
This is controlled by
CMSOffice2007DemoView::OnUpdateViewThumb
which callspCmdUI->Enable(FALSE);
. You can change this to callTRUE
orFALSE
at runtime to enable/disable the button respectively.