Thread: Check Box Question

  1. #1
    Yatta
    Guest

    Check Box Question

    In which part of my code do I test whether a check box has been clicked ?

    Here's some of my code:
    Code:
    // my own two functions:
    bool CheckBox(HWND hDlg, HWND button)
    {
    	if( SendMessage(hDlg, BM_GETCHECK, 0, 0) == BST_CHECKED )
    	{
    		return TRUE;
    	}
    	else
    	{
    		return FALSE;
    	}
    }
    
    
    void MakeActive(HWND hDlg, HWND winone, HWND wintwo)
    {
    	EnableWindow(winone, TRUE);
    	EnableWindow(wintwo, TRUE);
    }
    
    // the code to test the check box:
    	   if(CheckBox(hDlg, mon_check) == TRUE)
    	   {
    		   MakeActive(hDlg, mon_one, mon_two);
    	   }
    Thanks heaps

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    The help is unclear on this msg. I use IsDlgButtonChecked() macro instead from winuser.h.

    ie
    if(BST_CHECKED == IsDlgButtonChecked(hDialog , IDC_BUTTON) )

    AFAIK you need to send the HWND of the button not of the dlg if using SendMessage(). (Else how does it know which button you want to check?)

    When do you send the message?
    When you need to know if the button is checked. Probably when the user activates another control.
    "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

  3. #3
    Yatta
    Guest
    I want to see if its checked right after they check it

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    OK
    In the dialogs callback, under the WM_COMMAND case 's switch you will have a case for the button. Use the code there.

    Code:
    case WM_COMMAND:
    idControl = GET_WM_COMMAND_ID(wParam,lParam) ;
    switch(idControl)
    {
        case IDC_BUTTON:
        if (BN_CLICKED == HIWORD(wParam))
    //button has been clicked so now find its check state
    "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

  5. #5
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Like this

    Here it goes. The IDC_CHKBOX is a #define and is the button ID.

    bool CheckBox (HWND hWnd)
    {
    if (IsDlgButtonChecked (hWnd, IDC_CHKBOX))
    return TRUE;

    return FALSE;
    }
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>if (IsDlgButtonChecked (hWnd, IDC_CHKBOX))

    This will not work correctly as there is three returns from the macro

    0 = unchecked
    1 = checked
    2 = undetermined (also a true)

    not to mention if the #defined returns numeriacl value should be changed.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual Box
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 02-12-2009, 05:08 AM
  2. Quick input check question
    By Jozrael in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2009, 07:23 AM
  3. Message box / Structure question?
    By dxfoo in forum Windows Programming
    Replies: 5
    Last Post: 10-24-2005, 01:43 PM
  4. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  5. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM