c++ - Disable/Enable Ribbon Buttons for MFC Feature Pack -


I am using pack MFCs feature and a button I have ribbon bar, for example CMFCRibbonButton problem That I would like to enable and disable some of them in some situations, but how can I do this at runtime? Because there is no specific method to it ... I heard that will be attached to event handlers in order to find an alternative / different, but I do not know how ...

you must specify the associated command ID when you CMFCRibbonButton create objects, ( CMFCRibbonButton constructor) < / P>

For example, if you have a ribbon button whose command id is ID_MYCOMMAND , then enable the ribbon button. Disabling of MFC is done using the normal order updating mechanism. And you want to handle this command in the view class of your command, you must add the class of these functions:

  // MyView.h class CMyView: public CView {// ... Private: Afx_msg Zero Onam Commands (); Afx_msg zero ondate mycommand (CCMDUI * PCMDUI); DECLARE_MESSAGE_MAP ()};  

And to them. Implemented in the CPP file:

  // MyView.cpp void CMyView :: OnMyCommand () {// Add command handler code. } Zero CMyView :: OnUpdateMyCommand (CCmdUI * pCmdUI) {BOOL Enabled = ...; // Set the flag to enable or disable the command. PCmdUI-> Enable (enabled); }  

You must also add ON_COMMAND and ON_UPDATE_COMMAND_UI entries to the CMyView class message message:

  // MyView.cpp BEGIN_MESSAGE_MAP (CMyView, CView) ON_COMMAND (ID_MYCOMMAND, and CMyView :: OnMyCommand) ON_UPDATE_COMMAND_UI (ID_MYCOMMAND, and CMyView :: OnUpdateMyCommand) END_MESSAGE_MAP ()  

For more information about messaging maps in MFC, refer to MSDN.

I hope this helps!


Comments