title: Using WINAPI how do I change the value of a checkbox button?
body: <p>Currently I have a checkbox created in WM_CREATE:</p>
  
  <pre><code>hwndButtonPollFlag = 
  CreateWindow(
      TEXT("BUTTON"), 
      TEXT(sA.getMonitor(monitorSelected)-&gt;szDevice),
      WS_CHILD | WS_VISIBLE | SS_WHITERECT | BS_CHECKBOX, 
      0, 
      0, 
      0,
      0, 
      hwnd, 
      (HMENU)IDB_PollFlag, 
      hInstance, 
      NULL);
  </code></pre>
  
  <p>I am trying to change it's value whenever another button is clicked with:</p>
  
  <pre><code>    if (sA.getScreenArray(monitorSelected)-&gt;getPollFlag())
      {
          SetWindowLongPtr(hwndButtonPollFlag, GCL_STYLE, WS_VISIBLE | BST_CHECKED);
      }
      else
      {
          SetWindowLongPtr(hwndButtonPollFlag, GCL_STYLE, WS_VISIBLE | BST_UNCHECKED);
      }
      SetWindowText(hwndButtonPollFlag, TEXT(sA.getMonitor(monitorSelected)-&gt;szDevice));
  </code></pre>
  
  <p>This does change the text displayed next to the checkbox but not the actual state of the button. Also I would like the checkbox to have only two states (checked or unchecked) is there any other way to create that effect other than in the button return have something along the lines of:</p>
  
  <pre><code>switch (HIWORD(wParam))
      {
      case BST_CHECKED:
          sA.getScreenArray(monitorSelected)-&gt;setPollFlag(true);
          return 0;
      case BST_INDETERMINATE:
          if (sA.getScreenArray(monitorSelected)-&gt;getPollFlag())
          {
              SetWindowLongPtr(hwndButtonPollFlag, GCL_STYLE, WS_VISIBLE | BST_UNCHECKED);
          }
          else
          {
              SetWindowLongPtr(hwndButtonPollFlag, GCL_STYLE, WS_VISIBLE | BST_CHECKED);
          }
          return 0;
      case BST_UNCHECKED:
          sA.getScreenArray(monitorSelected)-&gt;setPollFlag(false);
          return 0;
      }
  </code></pre>
  
  <p>EDIT: As Mark Ransom said I used messages with the BM_GETCHECK and BM_SETCHECK flag as so:</p>
  
  <pre><code>    case IDB_MONITOR:
      monitorSelected = LOWORD(lParam);
      if (sA.getScreenArray(monitorSelected)-&gt;getPollFlag())
      {
          SendMessage(hwndButtonPollFlag, BM_SETCHECK, BST_CHECKED, NULL);
      }
      else
      {
          SendMessage(hwndButtonPollFlag, BM_SETCHECK, BST_UNCHECKED, NULL);
      }
      SetWindowText(hwndButtonPollFlag, TEXT(sA.getMonitor(monitorSelected)-&gt;szDevice));
      return 0;
  case WM_COMMAND:
      //sA.getScreenArray(monitorSelected)-&gt;setPollFlag(LOWORD(lParam));
      switch (LOWORD(wParam))
      {
      case IDB_PollFlag:
          if (SendMessage(GetDlgItem(hwnd, IDB_PollFlag), BM_GETCHECK, 0, 0) == BST_CHECKED)
          {
              SendMessage(hwndButtonPollFlag, BM_SETCHECK, BST_CHECKED, NULL);
              sA.getScreenArray(monitorSelected)-&gt;setPollFlag(true);
          }
          else {
              SendMessage(hwndButtonPollFlag, BM_SETCHECK, BST_UNCHECKED, NULL);
              sA.getScreenArray(monitorSelected)-&gt;setPollFlag(false);
          }
          break;
      }
      return 0;
  </code></pre>