Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a CCmdUI from a CButton

Status
Not open for further replies.

bulgakov

Programmer
Apr 24, 2003
26
GB
History:
Buttons on a dialog bar can not be enabled and disabled
(see KBA 152376).
The answer is to have a handler for ON UPDATE COMMAND UI
to the button

void CMainFrame::OnUpdateButton1(CCmdUI *p)
{
p->Enable(TRUE);
}

so this is great it works, now I want to disable this
button when the operator clicks on a different button,
ie

void CMainFrame::OnPlayButton()
{
//Enable the Pause button
ExecuteFile(...); // a method to play a file
}

But I can not enable the pause button ! So can I
call the OnUpdateButton1(CCmdUI *p)
method ? If so how do I get the CCmdUI pointer to the
CButton ?

Thanks.
 
You need to have access to the state in any way you like then use the state in the OnUpdateButton1() handler to enable/disable the button.

There may be another problem however of getting the framework to send the message when working with a dialog bar. There may be more Technical articles about this subject.

Or perhaps you can manually set it (enable/disable) in the OnPlayButton() function and also in the OnUpdateButton1() handler.

-pete
 
I am answering this myself to help anyone else who reads
this and has the same problem.

To call the CMainFrame::OnUpdateButton1(CCmdUI *p)

with the correct CCmdUI do this..

CCmdUI p;
p.m_pOther = (CWnd*)GetDlgItem(ID_OF_BUTTON);
OnUpdateButton1(&p);

The intuitive m_pOther name gave it away, and of course
the direct access to an attribute, no need for
methods in microsofts cut down version of OO
methodology.

Marcus.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top