When you create the CMFCRibbonButton object, you must specify the appropriate command identifier (see the documentation for the CMFCRibbonButton constructor here ). Turning ribbon buttons on and off is performed using the usual command update mechanism in MFC using the CCmdUI class.
For example, if you have a ribbon button with the command identifier ID_MYCOMMAND and you want to process this command in the application view class, you must add these functions to the class:
// MyView.h class CMyView : public CView { // ... private: afx_msg void OnMyCommand(); afx_msg void OnUpdateMyCommand(CCmdUI* pCmdUI); DECLARE_MESSAGE_MAP() };
and implement them in a .cpp file:
// MyView.cpp void CMyView::OnMyCommand() { // add command handler code. } void CMyView::OnUpdateMyCommand(CCmdUI* pCmdUI) { BOOL enable = ...; // set flag to enable or disable the command. pCmdUI->Enable(enable); }
You must also add the ON_COMMAND and ON_UPDATE_COMMAND_UI to the message map for the CMyView class:
For more information about message cards in MFC, see TN006: Message Cards on MSDN.
Hope this helps!
source share