Click to See Complete Forum and Search --> : disabling/enableing button control


mukesh
August 18th, 1999, 05:23 PM
I am trying simple thing of disabling and enabling button controls in dialog. Please give me some suggestion

August 18th, 1999, 05:29 PM
To disable button:

GetDlgItem(IDC_BUTTON_TEST)->EnableWindow(FALSE); /* TRUE to enable */

jbennett
August 18th, 1999, 05:33 PM
You want to use CWnd::EnableWindow() to do this.



void CDialog::somefunction()
{
CButton * myButton = (CButton *) this->GetDlgItem(idc);
myButton->EnableWindow(true); // enable the button
myButton->EnableWindow(false); // disable the button
}




idc is the IDC_ value for the control in question which you can get by going into the dialog resource editor and looking at the control's properties.

mukesh
August 18th, 1999, 05:34 PM
Thanks for your help.

mukesh
August 18th, 1999, 05:35 PM
Thanks alot for your help. I got it.

mukesh
August 18th, 1999, 05:40 PM
I was also trying to create and destroy buttons.
I tried using CButton::Create(). The button doesn't appear on the dialog box. And I do not know the reason. What is the right way of doing it

August 18th, 1999, 05:56 PM
Make sure to have a member or global variable for the control (not local to the function).

Example:

m_Button1.Create("test", WS_CHILD|WS_VISIBLE,...

or

m_pButton1 = new CButton();
m_pButton1->Create("test", WS_CHILD|WS_VISIBLE,...
make sure to delete m_pButton1 when you don't need it anymore