Click to See Complete Forum and Search --> : Enable/Disable button


mrRee
October 22nd, 2004, 04:47 AM
I had create button called IDC_PLAY on the design view in a dialog box call IDD_CONTROL. How can i disable it.

I had heard about EnableWindow(); but i don't know how to associate HWND for that button because i don't create the button on run-time. It's already in the dialog box.
Have anyone got some clue....

gstercken
October 22nd, 2004, 05:36 AM
I had heard about EnableWindow(); but i don't know how to associate HWND for that button because i don't create the button on run-time. It's already in the dialog box.
Have anyone got some clue....Yes - you can call GetDlgItem() to get the control's window handle.

NoHero
October 22nd, 2004, 09:04 AM
I had create button called IDC_PLAY on the design view in a dialog box call IDD_CONTROL. How can i disable it.

I had heard about EnableWindow(); but i don't know how to associate HWND for that button because i don't create the button on run-time. It's already in the dialog box.
Have anyone got some clue....

You also can use SendDlgItemMessage() with the ID of your button defined in resource.h:


// enable button IDC_BUTTON1 in dialog hDialog
SendDlgItemMessage(hDialog, IDC_BUTTON1, WM_ENABLE, (WPARAM)TRUE, 0);
// disable button:
SendDlgItemMessage(hDialog, IDC_BUTTON1, WM_ENABLE, (WPARAM)FALSE, 0);

mrRee
October 24th, 2004, 09:30 PM
Thanx all..
It's work. I use GetDlgItem() to get the button handle and enable/disable it with EnableWindow().

But if I use:

SendDlgItemMessage(hDialog, IDC_PLAY, WM_ENABLE, (WPARAM) FALSE, 0);

it didn't work. Am I missing something there? Actually I had try this method before I post this thread and it didn't work also..
Anyway, thanx again..

rafraf
May 5th, 2005, 07:53 AM
SendDlgItemMessage(hDialog, IDC_PLAY, WM_ENABLE, (WPARAM) FALSE, 0);

I have the same problem...if anyone knows why it does not work...???

by now I solve this with the folllowing:

EnableWindow(GetDlgItem(hDialog, IDC_PLAY), TRUE);

Bond
May 5th, 2005, 08:48 AM
WM_ENABLE is a notification message. It is sent to your parent window in response to the enabling/disabling of a child window. It cannot be used to alter it.

NoHero
May 5th, 2005, 03:10 PM
WM_ENABLE is a notification message. It is sent to your parent window in response to the enabling/disabling of a child window. It cannot be used to alter it.

I always mix those two up... :thumbd: ...

Quell
May 5th, 2005, 03:51 PM
Ws_disabled

Bond
May 5th, 2005, 04:03 PM
Ws_disabled
WS_DISABLED is a window style, not a message, and would have to be used in conjunction with SetWindowLong() to change the window's current style. I'm not even sure if it affects the window other than when it is initially created but one could test it.

Quell
May 5th, 2005, 05:37 PM
WS_DISABLED worlks after the application has been created//or can be made to work in a few cases....adn windows style is as good as a message is..

Bond
May 6th, 2005, 08:13 AM
adn windows style is as good as a message is..
It may be as effective, but I would think:

EnableWindow(hwnd, FALSE);

would be much more readable than:

LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, lStyle & WS_DISABLED);

I would only use WS_DISABLED if I wanted a window/control to be initially disabled during creation.