MFC: How to disable toolbar buttons
-
First I tried to enable and disable menu item's in main frame window like this: CMenu *m = GetMenu()->GetSubMenu(1); m->EnableMenuItem(ID_SCHEME_SELMOVE, bEnabled); m->EnableMenuItem(ID_SCHEME_HAND, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEUP, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEDOWN, bEnabled); This code didn't work until I've add this in frame constructor. CMainFrame::CMainFrame() { m_bAutoMenuEnable = FALSE; //disables auto menu enable } Now, I can't enable and disable toolbar buttons: m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SELMOVE, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_HAND, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEUP, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEDOWN, b); I think there is should be a mechanism to disable automatic toolbar enable. What is that mechanism?
-
First I tried to enable and disable menu item's in main frame window like this: CMenu *m = GetMenu()->GetSubMenu(1); m->EnableMenuItem(ID_SCHEME_SELMOVE, bEnabled); m->EnableMenuItem(ID_SCHEME_HAND, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEUP, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEDOWN, bEnabled); This code didn't work until I've add this in frame constructor. CMainFrame::CMainFrame() { m_bAutoMenuEnable = FALSE; //disables auto menu enable } Now, I can't enable and disable toolbar buttons: m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SELMOVE, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_HAND, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEUP, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEDOWN, b); I think there is should be a mechanism to disable automatic toolbar enable. What is that mechanism?
MFC is set up to not require you constantly maintain and update the state of the menu/toolbars. It asks you how to display the toolbars/menu item through update handlers. In the "wizard" where you set up a handler for the menu or toolbar, you can also choose to add an update handler that the system will call whenever displaying them. void CYourView::OnUpdateViewSomeMenuItem(CCmdUI *pCmdUI) { // TODO: Add your command update UI handler code here if (/*Some Condition*/) { pCmdUI->Enabled(TRUE); } else { pCmdUI->Enabled(FALSE); } // Also can set the checked state here if (/*Some Condition*/) { pCmdUI->SetCheck(TRUE); } }
-
First I tried to enable and disable menu item's in main frame window like this: CMenu *m = GetMenu()->GetSubMenu(1); m->EnableMenuItem(ID_SCHEME_SELMOVE, bEnabled); m->EnableMenuItem(ID_SCHEME_HAND, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEUP, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEDOWN, bEnabled); This code didn't work until I've add this in frame constructor. CMainFrame::CMainFrame() { m_bAutoMenuEnable = FALSE; //disables auto menu enable } Now, I can't enable and disable toolbar buttons: m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SELMOVE, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_HAND, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEUP, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEDOWN, b); I think there is should be a mechanism to disable automatic toolbar enable. What is that mechanism?
Can you use the regular MFC command enabling mechanism?
// add to message map
ON_UPDATE_COMMAND_UI(ID_SCHEME_SELMOVE, OnUpdateSchemeSelMove)
...
// Add to CMainFrame class
void CMainFrame::OnUpdateSchemeSelMove(CCmdUI* pCmdUI)
{
pCmdUI->Enable(false);
}Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
First I tried to enable and disable menu item's in main frame window like this: CMenu *m = GetMenu()->GetSubMenu(1); m->EnableMenuItem(ID_SCHEME_SELMOVE, bEnabled); m->EnableMenuItem(ID_SCHEME_HAND, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEUP, bEnabled); m->EnableMenuItem(ID_SCHEME_SCALEDOWN, bEnabled); This code didn't work until I've add this in frame constructor. CMainFrame::CMainFrame() { m_bAutoMenuEnable = FALSE; //disables auto menu enable } Now, I can't enable and disable toolbar buttons: m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SELMOVE, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_HAND, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEUP, b); m_wndViewToolBar.GetToolBarCtrl().EnableButton(ID_SCHEME_SCALEDOWN, b); I think there is should be a mechanism to disable automatic toolbar enable. What is that mechanism?