Thread: Obtaining and Setting a Checkbox State

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    387

    Obtaining and Setting a Checkbox State

    Does anyone know how to get the Checkbox state, if it is NOT in a dialog box? I have this code, but its not working..

    Code:
    	case WM_COMMAND:
    		{
    			switch(LOWORD(wParam))
    			{
    			case IDC_START:
    				{
    					UINT cLogoff;
    					cLogoff = IsDlgButtonChecked(hLogoff, IDC_LOGOFF);
    					
    					if(cLogoff == BST_CHECKED)
    					{
    						CheckDlgButton(hShutdown, IDC_SHUTDOWN, BST_UNCHECKED);
    						CheckDlgButton(hRestart, IDC_RESTART, BST_UNCHECKED);
    						bLogoff = true;
    						bShutdown = false;
    						bRestart = false;
    					}
    				}
    				break;
    			}
    		}
    		break;
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    I think that BST_CHECKED is a flag that is part of a mask, so doing this:

    cLogoff == BST_CHECKED

    isn't necessarily going to be true (depends on the rest of the mask).

    so try this:

    Code:
    if(cLogoff & BST_CHECKED)
    {
       // do stuff
    }
    good luck
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I use that macro, in the way you used it, without problem.

    Is that case statement entered if you click the radio button? (are the msg's going to this callback)

    >>IsDlgButtonChecked(hLogoff, IDC_LOGOFF);

    Is hLogoff the parent HWND (as it should)
    or
    the buttons HWND (which it shouldn't, but looks like)?



    EDIT: This is my 1000 post, do I get a GovtCheese doll or something?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    > Is hLogoff the parent HWND (as it should)
    Ohhh its the hWnd of the button.

    What does the & operator do? check to see if its true?
    [EDIT] Nevermind, i think i know what it does, but if im wrong you can still correct me , does it: Check to see if that flag is part of it?
    example:
    Code:
    UINT uInt;
    uInt = BLAH_BLAH | HALB_HALB;
    
    if(uInt & BLAH_BLAH)
         MessageBox(NULL, "BLAH_BLAH IS SET", "Information", MB_OK);
    [/EDIT]
    Last edited by Okiesmokie; 05-13-2002 at 01:02 AM.
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    yup, correctamundo.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed