 |
NEWBIE
TIP
#4
Disabling a control at runtime
This one's way too easy. Remember that a control is really just a
window. When you're getting a pointer to a control, you're getting a
pointer to its window (Tip #3 includes an
example of this). GetDlgItem gives you a pointer to a control's window;
once you have it, simply call EnableWindow, sending TRUE or FALSE to
enable or disable it.
Note: this will not work for push-button controls on a DialogBar. See MSKB article
Q152376
for more details.
// Get a pointer to the control's window.
CWnd *p = GetDlgItem(IDC_MYCONTROL);
// Disable the control.
p->EnableWindow(FALSE);
// Enable the control.
p->EnableWindow(TRUE);
|
Source code
is provided for instructional purposes,
and is released to the public domain.
No claim of ownership is made.
Use it at your own risk.
No warranties are expressed or implied.
The resulting program may not be fully functional.
No animals were used to test this code.
|
Past Tips |
Future Tips |
Home |
Comments on this Tip?
Send us mail.
(Be sure to put the Tip # in the subject.)
Got an idea for a Tip you'd like us to write?
Let us know.
Solved a problem lately that would make a good Tip?
PLEASE tell us about it!!!
We'll give you prominent credit, and we'll even buy you a beer next time you're in town.
|