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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I disable or "gray-out" a checkbox from within a function?

Status
Not open for further replies.

klharvey

Programmer
May 1, 2003
7
US
I have several checkboxes in a dialog box that I want to disable until the user selects an item from a combobox. The only way I can find to disable a checkbox is from the properties window within ClassWizard.
 
Look for "EnableWindow" in the library and you will find what you need.

Marcel
 
Just call "EnableWindow" function on your checkbox. For example, if your checkbox is named "MyCheckBox", you will use this call in your function.

Code:
MyCheckBox.EnableWindow(FALSE);

So if you have 10 checkboxes, you will call this function for each of them. A checkbox is a window and you can use CWnd functions (EnableWindow is a CWnd function) on them. Check CWnd details in MSDN for more details about it.

When you need to enable these checkboxes at any point, i.e. when your user selects an item from a combobox, call EnableWindow again with parameter TRUE passed to it. Like

Code:
MyCheckBox.EnableWindow(TRUE);

or

MyCheckBox.EnableWindow(); // EnableWindow takes TRUE as default parameter, if none is supplied.

Hope this helps.
 
That did it. I forgot that every object is a little window. Tanks to both.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top