Invoke OnUpdateButton1(CCmdUI* pCmdUI)???
In a dialog based application I've added a toolbar.
Member variable: CToolBar m_wndToolBar;
BOOL CTestDlg::OnInitDialog()
{
...
m_wndToolBar.Create(this);
m_wndToolBar.LoadToolBar(IDR_TOOLBAR1);
m_wndToolBar.ShowWindow(SW_SHOW);
m_wndToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_FLOATING);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
...
}
then using class wizard i've added two functions for each button:
void CTestDlg::OnButton1()
{
.....
}
void CTestDlg::OnUpdateButton1(CCmdUI* pCmdUI)
{
.....
}
There is no problem to invoke OnButton1() while pressing Button1.
What should I add to code to invoke OnUpdateButton1(CCmdUI* pCmdUI)???
Thanks in advance.
Re: Invoke OnUpdateButton1(CCmdUI* pCmdUI)???
I am not quite sure what you mean, so I'll discuss the two possibilities that spring to mind:
1) If you think you need OnUpdateButton1() and are asking what should go in it, the answer is: You don't need it. OnUpdate...() handlers are used to say whether the control should be enabled or not. The MFC framework automatically enables the control if it finds a handler (OnButton1() in your case), or disables it if no handler is found IN THE WINDOW CLASS WHICH IS THE PARENT OF THE TOOLBAR.
What needs to go in there is
pCmdUI->Enable(enabled_state);
to say whether or not you want it enabled (TRUE) or disabled (FALSE).
2) If you are saying that you want to use the OnUpdate...() but it is not being called, it is probably a CDialog thing. In this situation I would manually enable and disable it based on the criteria you set for its enabling.
Does this help?