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. How to use GetToolBarCtrl().EnableButton?

How to use GetToolBarCtrl().EnableButton?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestionannouncement
7 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.
  • L Offline
    L Offline
    louis 0
    wrote on last edited by
    #1

    I am trying to enable or disable a toolbar button during runtime without clicking on the toolbar itself. When a condition in some other file changes I would like to toggle the toolbar button accordingly. The OnUpdateHandler that the Wizard uses does seem to update. I am using the CToolbar::GetToolbarCtrl() and CToolbarCtrl::EnableButton(nID, FALSE) because I'm working in different files, calling a function in CMainFrame. However, the return value from EnableButton is FALSE. Why is this?? Can anyone please tell me what I am doing wrong??? m_MyToolbar is the CToolbar object which successfully has loaded my toolbar in my application. Now I just want to enable/disable a button on this toolbar... file_A.cpp void function file_A () { cMainFrame MainFrame; .... .... int nSuccess = MainFrame.m_MyToolbar.GetToolbarCtrl().EnableButton(ID_BUT1,FALSE); ... ... } Any help appreciated..! Thank you. :( :( :)

    N M 2 Replies Last reply
    0
    • L louis 0

      I am trying to enable or disable a toolbar button during runtime without clicking on the toolbar itself. When a condition in some other file changes I would like to toggle the toolbar button accordingly. The OnUpdateHandler that the Wizard uses does seem to update. I am using the CToolbar::GetToolbarCtrl() and CToolbarCtrl::EnableButton(nID, FALSE) because I'm working in different files, calling a function in CMainFrame. However, the return value from EnableButton is FALSE. Why is this?? Can anyone please tell me what I am doing wrong??? m_MyToolbar is the CToolbar object which successfully has loaded my toolbar in my application. Now I just want to enable/disable a button on this toolbar... file_A.cpp void function file_A () { cMainFrame MainFrame; .... .... int nSuccess = MainFrame.m_MyToolbar.GetToolbarCtrl().EnableButton(ID_BUT1,FALSE); ... ... } Any help appreciated..! Thank you. :( :( :)

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      have you done this? MainFrame=AfxGetMainWnd(); Nish Sonork ID 100.9786 voidmain
      www.busterboy.org
      Nish is a BIG fan of Goran Ivanisevic

      L 1 Reply Last reply
      0
      • L louis 0

        I am trying to enable or disable a toolbar button during runtime without clicking on the toolbar itself. When a condition in some other file changes I would like to toggle the toolbar button accordingly. The OnUpdateHandler that the Wizard uses does seem to update. I am using the CToolbar::GetToolbarCtrl() and CToolbarCtrl::EnableButton(nID, FALSE) because I'm working in different files, calling a function in CMainFrame. However, the return value from EnableButton is FALSE. Why is this?? Can anyone please tell me what I am doing wrong??? m_MyToolbar is the CToolbar object which successfully has loaded my toolbar in my application. Now I just want to enable/disable a button on this toolbar... file_A.cpp void function file_A () { cMainFrame MainFrame; .... .... int nSuccess = MainFrame.m_MyToolbar.GetToolbarCtrl().EnableButton(ID_BUT1,FALSE); ... ... } Any help appreciated..! Thank you. :( :( :)

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        You're making a new CMainFrame object? That's the problem. You need to access the existing CMainFrame which is your main window:

        ((CMainFrame*) AfxGetMainWnd())->m_MyToolbar.GetToolbarCtrl().EnableButton(ID_BUT1,FALSE);

        --Mike-- http://home.inreach.com/mdunn/ #include "witty_sig.h" :love: your :bob: with :vegemite: and :beer:

        L 1 Reply Last reply
        0
        • N Nish Nishant

          have you done this? MainFrame=AfxGetMainWnd(); Nish Sonork ID 100.9786 voidmain
          www.busterboy.org
          Nish is a BIG fan of Goran Ivanisevic

          L Offline
          L Offline
          louis 0
          wrote on last edited by
          #4

          Thanks. Where do you want me to put this code, and what does it do MainFrame=AfxGetMainWnd(); Kind regards

          N 1 Reply Last reply
          0
          • L louis 0

            Thanks. Where do you want me to put this code, and what does it do MainFrame=AfxGetMainWnd(); Kind regards

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            AfxGetMainWnd() returns a pointer to your Main frame window CMainFrame *a= (CMainFrame*)AfxGetMainWnd(); a->tbar.GetToolBarCtrl().whateverfunction Nish Sonork ID 100.9786 voidmain
            www.busterboy.org
            Nish is a BIG fan of Goran Ivanisevic

            L 1 Reply Last reply
            0
            • N Nish Nishant

              AfxGetMainWnd() returns a pointer to your Main frame window CMainFrame *a= (CMainFrame*)AfxGetMainWnd(); a->tbar.GetToolBarCtrl().whateverfunction Nish Sonork ID 100.9786 voidmain
              www.busterboy.org
              Nish is a BIG fan of Goran Ivanisevic

              L Offline
              L Offline
              louis 0
              wrote on last edited by
              #6

              Thank you. It works fine now. Kind regards.:) ;) ;P

              1 Reply Last reply
              0
              • M Michael Dunn

                You're making a new CMainFrame object? That's the problem. You need to access the existing CMainFrame which is your main window:

                ((CMainFrame*) AfxGetMainWnd())->m_MyToolbar.GetToolbarCtrl().EnableButton(ID_BUT1,FALSE);

                --Mike-- http://home.inreach.com/mdunn/ #include "witty_sig.h" :love: your :bob: with :vegemite: and :beer:

                L Offline
                L Offline
                louis 0
                wrote on last edited by
                #7

                Thank's a lot. It works fine. Kind regards. :) :) :)

                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