Re: Disable Toolbar Button
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
[email protected]
Re: Disable Toolbar Button
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
Re: Disable Toolbar Button
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
[email protected]
Re: Disable Toolbar Button
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.