Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
hi all,
i've a button. i want to enable and disable that button based on some conditions. how can i enable and disable the button through code.please help me..
Posted

use the EnableWindow(...)[^] function, or method, depending on thr framework you're using (raw/MFC/ATL)

EnableWindow(hWindow,FALSE);
or
CWnd.EnableWindow(FALSE);
or
CWindow.EnableWindow(FALSE);

will disable the window
 
Share this answer
 
Comments
Nithin Sundar 1-Jun-11 7:09am    
My 5!
Jijesh Balakrishnan 1-Jun-11 7:14am    
i'm using MFC
Nithin Sundar 1-Jun-11 7:17am    
That doesn't make a difference. MFC is basically a wrapper around win32.
Jijesh Balakrishnan 1-Jun-11 7:18am    
thank you..
Joan M 1-Jun-11 12:10pm    
Simple and direct... 5ed!
Adding to the solution of Barneyman, if you're using Win32, you can use something like:

GetDlgItem (YOUR_CONTROL_ID_HERE)->EnableWindow(FALSE);


or the other alternate:

CWnd* myControl = GetDlgItem (YOUR_CONTROL_ID_HERE);

if(myControl)
{
    myControl->EnableWindow (FALSE);
}
 
Share this answer
 
Comments
Jijesh Balakrishnan 1-Jun-11 7:17am    
Thank you..
try this:

if(condition1)
{
buttonName.enabled=false;
}
 
Share this answer
 
Comments
Jijesh Balakrishnan 1-Jun-11 7:10am    
no.its showing the following error. error C2228: left of '.EnableWindow' must have class/struct/union type
Nithin Sundar 1-Jun-11 7:15am    
I think this is suitable only for .NET. Please clarify this!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900