Вопрос

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top