Thread: Check state of buttons

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    37

    Check state of buttons

    I used this code to get the state of a checkbox but it only check for its state as the window is intialised...So I wonder how to make it get the state each time the function contain the SendMessage is accessed.

    Code:
     if(SendMessage(hwnd,BM_GETCHECK,0,chk1)!=BST_CHECKED)
      {
       //process
      }

    Any simple guidance..even keywords to guide my search are welcomed..Thx

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    37

    one way to monitor button click, any others?

    I figured one way of doing it...by using a flag and setting its status when the checkbox has been clicked

    I used this code in the case WM_COMMAND


    Code:
    case chk1:
    { 
          if(IsDlgButtonChecked(hwnd,chk1)==BST_CHECKED)
                status=1;
                else
                status=0;
    }break;
    Howver I still wonder if the state can be monitored out of the switch message, in another function.

  3. #3
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    The LPARAM of the BM_GETCHECK message should be 0. If hwnd isn't the handle to your checkbox you won't get what you want. There's a function that can retrieve the HWND of a control by specifying the parent window and the control's resource, but I don't remember right now.
    Howver I still wonder if the state can be monitored out of the switch message, in another function.
    Depends on what you mean by monitor. Sending a message to retrieve the value when needed is usually sufficient.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Class Design question.
    By g4j31a5 in forum C++ Programming
    Replies: 10
    Last Post: 11-08-2006, 10:28 PM
  3. Check application visibility
    By 3saul in forum Linux Programming
    Replies: 2
    Last Post: 02-13-2006, 05:13 PM
  4. Ownerdraw buttons (2)
    By maes in forum Windows Programming
    Replies: 7
    Last Post: 09-11-2003, 05:50 AM
  5. Radio Buttons in Visual C++ 6
    By Ripper1 in forum Windows Programming
    Replies: 22
    Last Post: 05-16-2003, 07:54 AM