-
Get Button State
hey, i'd like to know how i would go about getting the state of a button. what i need to do is check if all of the buttons (id's 500 - 512) are disabled and if they are, do stuff. if not, do nothing. i was thinking about using a SendMessage and sending WS_DISABLED to see if it would return true or false but A. i dont think thatd workd and B. i dont know if it needs a WPARAM & LPARAM. lol
thanks
<edit>
for some reason this function doesn't work :( ....
Code:
void GameCheck(HWND hwnd)
{
int i = 500, enabled = 0;
for (i = 500; i <= 512; i++)
{
if (EnableWindow(GetWindow(hwnd, i), FALSE) == 0)
{
EnableWindow(GetWindow(hwnd, i), TRUE);
++enabled;
}
}
if (enabled == 0)
{
EnableDisable(hwnd, FALSE, 513, 0);
MessageBox(NULL, "Game Over :)\nThanks for playing!\nYou can save the\nending stats if you'd like.",
"Done", MB_OK | MB_ICONEXCLAMATION);
}
}
bed time :)
-
-
Also just to let you know all windows messages are documented on MSDN just search for them. That'll tell you if it needs WPARAM or LPARAM and what should be in the hibytes/lobytes, if needed.
-
i did search it but i wasn't coming up with anything so i stopped searching. lol
thanks :)
its not working :(
Code:
void GameCheck(HWND hwnd)
{
int i = 600, enabled = 0;
for (i = 600; i <= 617; i++)
{
if (IsWindowEnabled(GetDlgItem(hwnd, i)) != 0)
{
++enabled;
}
}
if (enabled == 0)
{
HMENU hMenu, hFileMenu;
hMenu = GetMenu(hwnd);
hFileMenu = GetSubMenu(hMenu, 0);
EnableMenuItem(hFileMenu, 2, MF_BYPOSITION | MF_ENABLED);
EnableDisable(hwnd, FALSE, 513, 0);
MessageBox(NULL, "Game Over :)\nThanks for playing!\nYou can save the\nending stats if you'd like.",
"Done", MB_OK | MB_ICONEXCLAMATION);
}
}
am i doing something wrong?
-
The code looks fine. Obviously, it relies on other parts of the program. What is going wrong? Does enabled give the correct count after the loop? You could try putting a MessageBox call in the loop to check which buttons are enabled and which are not. This might show something up.
-
LMAO....so i added some code to my ++enabled area..
Code:
if (IsWindowEnabled(GetDlgItem(hwnd, i)) != 0)
{
_itoa(i, intchar, 10);
strcat(hEnabled, intchar);
MessageBox(NULL, hEnabled, "Enabled", MB_OK);
++enabled;
hEnabled[37] = 0;
hEnabled[38] = 0;
hEnabled[39] = 0;
}
and i declared hEnabled to be initialied with the text "The control with this id is enabled: " so when the message box popped up and said "The control with this id is enabled: 600" i thought to myself...600? that doesn't sound right...aren't the 600's the static controls and the 500's the buttons??
...yea...you can see where it goes from there... lol thanks :-D i usually try that for error checking but for some reason this time i didn't..
mm...it also doesn't help that i was having it check if the buttons were disabled BEFORE i disabled the button which was pushed, lol