Click to See Complete Forum and Search --> : how disable button ?
August 31st, 1999, 03:13 PM
how can i disable a CButton object ?
i know how to disalbe CImageButton
but it not working in the CButton.
i use dialog project .
pascal!
August 31st, 1999, 03:19 PM
GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
where IDC_BUTTON1 is the control ID of the button to be disabled.
August 31st, 1999, 03:27 PM
If you have a member variable associated with the button, you can also do this:
CButton m_ButtonOne
m_ButtonOne.EnableWindow(TRUE);
if(m_ButtonOne.IsWindowEnabled())
m_ButtonOne.EnableWindow(FALSE);
// etc.
Robert H.
August 31st, 1999, 04:20 PM
If you want to disable the button on startup, just use the resource editor to disable the button (go to properties, and click on the DISABLE checkbox) - This is provided you are using some version of VC++. If you aren't, you will have to disable the button using the method explained in the first reply. (I just thought this way would be easier if you are using VC++).
And to disable/enable the button during the program, I usually do this:
CButton* pBut = static_cast<CButton*>(GetDlgItem(IDC_BUTTON1));
pBut->EnableWindow(TRUE);
pBut->EnableWindow(FALSE);
where IDC_BUTTON1 is the resource ID name.
Hope that helps.
John Killingbeck
August 31st, 1999, 09:31 PM
I assume that your button has an ID associated with it and you are using Visual Studio for development. Here is the most conventional process, step by step. First, in your view class use ClassWizard to select your button ID from your Object ID's list. Then use ClassWizard to create an update handler function by selecting UPDATE_COMMAND_UI from the Messages: list. Your new function will be named CxxxView::OnUpdateXxxx with Xxxx being your button ID. Next inside the new function create and if() statement with the condition being whatever turns your button on/off (your choice) and an else statement for the opposite condition. Then inside the enable part of the if/else pair put the statement pCmdUI->Enable( TRUE ); and in the other section of your if/else pair put pCmdUI->Enable( FALSE );
These statements are exact. pCmdUI is the pointer sent to the handler by Windows. Here is an example I use to enable/disable a menu item/toolbar button:
void CMandelbrotView::OnUpdateRetrieve5(CCmdUI* pCmdUI)
{
// If the parameter array is in use then enable it.
if ( parameterArray.GetSize() > 4 )
pCmdUI->Enable( TRUE );
else
pCmdUI->Enable( FALSE );
}
This enables/disables the object based on the size of an array.
HTH.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.