Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC: How to disable toolbar buttons

MFC: How to disable toolbar buttons

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    progDes
    wrote on last edited by
    #1

    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?

    B M P 3 Replies Last reply
    0
    • P progDes

      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?

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      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); } }

      1 Reply Last reply
      0
      • P progDes

        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?

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        1 Reply Last reply
        0
        • P progDes

          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?

          P Offline
          P Offline
          progDes
          wrote on last edited by
          #4

          Thanks a lot, that was helpful.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups