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

How do you disable pushbuttons?????(urgent)

Status
Not open for further replies.

LanyA

Programmer
Jan 29, 2003
23
0
0
US
Hi - I'm new to MFC, so hopefully this is an easy one...I'm trying to write code that will disable a pushbutton once the user clicks it, and it should remain disabled until the task it triggered is completed. Everything works except for the disabling. I used EnableWindow() to gray out the button, however even though the button is grayed out it still performs the task when it is clicked. Can anyone help with this?
 
The [tt]EnableWindow()[/tt] should work! Can you post your code so we can see what's going on.

:)
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Here's the relevant code:

case IDC_SIGNANDSEND://This is the button I'm trying to get to disaable...
{

if (IsWindowEnabled(GetDlgItem(wnd,IDC_SIGNANDSEND))!=0)
{
//disable SignAndSend button
EnableWindow(GetDlgItem(wnd,IDC_SIGNANDSEND),false);
//do stuff
...
//reenable SignAndSend button
EnableWindow(GetDlgItem(wnd,IDC_SIGNANDSEND),true);
}
}Thanks
 
Try getting a pointer to your button first and use CWnd::EnableWindow() instead to see if that works:[tt]

CButton* myBtn = (CButton*)GetDlgItem(IDC_SIGNANDSEND);
myBtn->EnableWindow(FALSE);[/tt]

You mentioned you were new to MFC so I'm assuming that's how you created your dialog that contains the button. Otherwise, it looks like you're using box-standard API calls in your code when it may be easier to just use the MFC.
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
That was a misprint I'm actually using the standard API
Maybe I could rewrite all the code using MFC... though it might be more effort than it's worth since all I need is to be able to disable a button. Thanks for that
 
OK, try putting the 'true' and 'false' in uppercase and see if that works[tt]

EnableWindow(GetDlgItem(wnd,IDC_SIGNANDSEND),FALSE);[/tt]

If not, then separate the two calls and check that you are getting a valid HWND to the button:[tt]

HWND btn = GetDlgItem(wnd,IDC_SIGNANDSEND);
// check validity of 'btn' here in debugger
EnableWindow(btn,FALSE);[/tt]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
I tried that and it didn't work :(
 
What was the state of 'btn' HWND in the debugger? Did the code actually get called?
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Yes - the code got called, because the button actually grayed out while the code was running and went back to normal after it was done
 
I'm so used to using MFC I'm not that clued up on using regular API calls only. The button is getting grayed out but you can still click it. That's weird!! Have you tried posting this is in the 'Win API (Microsoft)' forum???
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Just click on the Forum List link towards the top list and it's somewhere under programming - sorry we couldn't cure it for you [cry]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top