Click to See Complete Forum and Search --> : How to enable\disable a button at runtime
August 12th, 1999, 11:24 PM
Im new to VC++ and I've been wondering how you can enable\disable a button at runtime. For example I would like to disable a button(I'm not talking about a toolbar button) when a text box is blank and enable it when a user enters text (like the Run program in the start menu). I think that it has something to do with the EnableButton function, but im not really sure. Thanks for the help.
Gregory64
August 12th, 1999, 11:32 PM
You have to get a pointer to your button and after this use
pBut->EnableWindow(FALSE);
August 12th, 1999, 11:54 PM
When you make a pointer to your button you do this in classwizard under member variables right? Because when I do that, i get the following compile errors:
error C2819: type 'CButton' does not have an overloaded member 'operator ->'
error C2227: left of '->EnableButton' must point to class/struct/union
Thanks.
Gregory64
August 13th, 1999, 12:06 AM
I assume that we are somewhwre in your class dialog wich contain your button
CButton* pBut=(CButon*)GetDlgItem(IDC_BUTTON);
pBut->EnableWindow(FALSE);
of corse IDC_BUTTON is ID of your button, you may check for its name in resurs editor.
August 13th, 1999, 12:16 AM
Thanks for you help. It worked. But I have one more thing to ask. How do you make it so you can toggle it? Like when you click on one button to enable or disable it.
Thanks.
Keon Park
August 13th, 1999, 12:19 AM
If you create a member variable (m_button for example) from Class Wizard, you have to enter:
m_button.EnableWindow(FALSE);
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.