Thread: Get Button State

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    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
    Last edited by willc0de4food; 10-09-2005 at 04:14 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    IsWindowEnabled

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    28
    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.

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    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?
    Last edited by willc0de4food; 10-09-2005 at 02:08 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    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.

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    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
    Last edited by willc0de4food; 10-09-2005 at 08:00 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grammar to FSA to C code (Newbie)
    By aybe in forum C Programming
    Replies: 4
    Last Post: 02-29-2008, 02:10 PM
  2. input/switch statement issues
    By peanut in forum C Programming
    Replies: 5
    Last Post: 10-27-2006, 02:58 PM
  3. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  4. Looking at current mouse button state
    By Lifedragn in forum C# Programming
    Replies: 4
    Last Post: 12-02-2005, 06:52 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM