简体   繁体   中英

Enabling\disabling CMFCToolBar buttons when embedded in pane

I know the best way to enable/disable a button from CMFCToolBar is to use

  int b_id = m_ToolBar.CommandToIndex(ID_BUTTON);
    m_ToolBar.SetButtonStyle(b_id,TBBS_DISABLED);

but that does not seem to work when the toolbar is embedded inside a CDockable Pane I have a derived class for CMFCToolBar which is required to enable the buttons in a pane but nothing I have tried will disable them.

OK I found the only solution was not to use the standard methods of disabling the buttons but to put the conditions in each of the on command update functions and use pCmdUI->Enable(FALSE); not much unlike what you would do to menus.

I know the topic is some years old, but i found another way you can do this is to inherit CMFCToolBar and make the following overwrite:

  ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)      

      afx_msg LRESULT OnIdleUpdateCmdUI(WPARAM wParam, LPARAM lParam) {
        return __super::OnIdleUpdateCmdUI(0, lParam);
      }

Then use the button style TBBS_DISABLED to enable/disable button - followed by calling AdjustLayout() for updating. This way you don't need an update handler for every single button.

PS. the 'wparam' controls if disabling when no handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM