i have built a simple window with a button in it and when i click the button i want to disable it, i have tried to use EnableWindow(GetDlgItem(hwnd, button1), 0); but this does not work and also gives me an error when compiling :
error: invalid conversion from `HWND__*' to `int'
error: initializing argument 2 of `HWND__* GetDlgItem(HWND__*, int)'
The GetDlgItem function takes a handle to the dialog window and the second parameter is the ID of the dialog item and return s the HWND of the item.
You are passing a handle to a window as the second item.
So it should be: EnableWindow(GetDlgItem(hwnd, 1), false); //ID of button, NOT the handle
Anyway, you don't need to use GetDlgItem function, because in the WM_COMMAND, if the
message is generated by a child window, then the ID is LOWORD(wParam), and lParam is
the child window handle.
1 2 3 4 5 6
case WM_COMMAND:
if (LOWORD(wParam) == 1 ) //check wParam against child window ID
{
EnableWindow( (HWND)lParam, false);
}
break;
Thanks for your answer aswell Disch i did try your way but although the compiler gave me no errors it just never done anything when i clicked the button but that could be my fault as you havent seen the rest of the code.
Thanks again for your help guys very much appreciate it
Thanks for your answer aswell Disch i did try your way but although the compiler gave me no errors it just never done anything when i clicked the button but that could be my fault as you havent seen the rest of the code.
For that particular solution:
HWND button1; declaration would would have to be changed to either
a. global variable
b. static local variable in the windows procedure.