I am trying simple thing of disabling and enabling button controls in dialog. Please give me some suggestion
Printable View
I am trying simple thing of disabling and enabling button controls in dialog. Please give me some suggestion
To disable button:
GetDlgItem(IDC_BUTTON_TEST)->EnableWindow(FALSE); /* TRUE to enable */
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.
Thanks for your help.
Thanks alot for your help. I got it.
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
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