Click to See Complete Forum and Search --> : Disable Toolbar Button
Kyle Eberle
May 28th, 1999, 03:25 PM
I am attempting to temporarily disable a toolbar button from within my application.
I tried this...
CToolBarCtrl& toolbar = m_wndToolBar.GetToolBarCtrl();
toolbar.EnableButton(ID_NEXT, FALSE);
However, it only disables the button while still within the scope of that function.
As soon as that function returns the button is enabled again.
I am sure that I am missing something simple, but I can't figure out what exactly.
What do I need to do to force the button to be disabled until I actually want
it enabled again?
Please help!!!
Thanks,
Kyle
Chris Wheeler
May 28th, 1999, 03:40 PM
Why not just use:
m_wndToolBar.EnableButton(ID_NEXT, FALSE);
I don't know if this is the case, but maybe your local variable "toolbar" is out of scope once the function completes.
Chris R. Wheeler, MCP
Pensacola Christian College
Desktop Programmer
cwheeler@pcci.edu
Kyle Eberle
May 28th, 1999, 04:35 PM
Chris,
Thank you for your response. I apologize if my questions seem
a bit dense, but I don't deal with the ToolBar very often.
m_wndToolBar is a CToolBar object and EnableButton is not a member of it.
I used the GetToolBarCtrl function to get a reference to the CToolBarCtrl.
EnableButton is a member of CToolBarCtrl.
Since GetToolBarCtrl returns a reference the m_wndToolBar object
is the fact that the CToolBarCtrl is out of scope an issue? I thought
that by referencing the underlying control I didn't have to have the
CToolBarCtrl defined.
I tried defining toolbar as a CToolBarCtrl object in the header
and then using the GetToolBarCtrl to reference the CToolBar
object, but I ended up with the same result.
Am I missing something fundamental about this control?
Thanks,
Kyle
Chris Wheeler
May 31st, 1999, 09:03 AM
Maybe you've solved this since I was out all weekend, but I'll suggest this anyway. Create a Message Handler in your mainframe for the button's command ID. Use UPDATE_COMMAND_UI. Then, in the handler, put this:
pCmdUI->Enable(TRUE);
That will enable the button so that it isn't gray and can be clicked on. You then have to create a message handler for the COMMAND of that button.
Chris R. Wheeler, MCP
Pensacola Christian College
Desktop Programmer
cwheeler@pcci.edu
Kyle Eberle
June 1st, 1999, 09:51 AM
Thanks Chris.
I will paste in what I ended up doing, just in case someone else is trying
to accomplish this and reads this conversation.
First added a handler for the ON_UPDATE_COMMAND_UI in the MainFrame class
ON_UPDATE_COMMAND_UI(ID_FIRST, UpdateRequery)
Then, I added the actual function. Since I wanted the button enabled while there was
a valid database connection and disabled when they had disconnected I just used the
IsOpen function in CDatabase to determine whether the buttons Enable status
should be TRUE or FALSE.
void CMainFrame::UpdateRequery(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_db.IsOpen());
}
Then, when I close the database (menu option) I just make sure
to update the FrameWnd.
m_db.Close();
m_wndToolBar.OnUpdateCmdUI(this, TRUE);
Thats it. The actual function mapped to ID_FIRST is actually in the View class,
but enabling or disabling the button in the FrameWnd class prevents that message altogether.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.