How to use GetToolBarCtrl().EnableButton?
-
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. :( :( :)
-
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. :( :( :)
have you done this? MainFrame=AfxGetMainWnd(); Nish Sonork ID 100.9786 voidmain
www.busterboy.org
Nish is a BIG fan of Goran Ivanisevic -
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. :( :( :)
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:
-
have you done this? MainFrame=AfxGetMainWnd(); Nish Sonork ID 100.9786 voidmain
www.busterboy.org
Nish is a BIG fan of Goran Ivanisevic -
Thanks. Where do you want me to put this code, and what does it do MainFrame=AfxGetMainWnd(); Kind regards
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 -
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 -
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: