title: Winapi creating a tab menu
body: <p>I'm trying to make a tab menu, it should have an active state with different styling when a tab is selected, the problem is when starting the program the tabs get selected after two clicks. When displaying the contents of the buttonPressed array in WM_DRAWITEM even, is a delay in changing the value of the active state                           </p>
  
  <pre><code>case WM_CREATE:
  
      buttonPressed[0] = 1;
      buttonPressed[1] = 0;
      buttonPressed[2] = 0;
      buttonPressed[3] = 0;
  
      button1 = CreateWindow("BUTTON","Overview",WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, 0,0,200,50, hwnd , (HMENU) 1 , NULL, NULL);
      button2 = CreateWindow("BUTTON","Send",WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, 200,0,200,50, hwnd , (HMENU) 2, NULL, NULL);
      button3 = CreateWindow("BUTTON","Receive",WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, 400,0,200,50, hwnd , (HMENU) 3, NULL, NULL);
      button4 = CreateWindow("BUTTON","Transactions",WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, 600,0,200,50, hwnd , (HMENU) 4, NULL, NULL);
  
  break;
  
  case WM_DRAWITEM:
          {
              if((wParam == 1 &amp;&amp; buttonPressed[0] == 1) ||  (wParam == 2 &amp;&amp; buttonPressed[1] == 1) || (wParam == 3 &amp;&amp; buttonPressed[2] == 1) || (wParam == 4 &amp;&amp; buttonPressed[3] == 1)   ){
                  FillRect(Item-&gt;hDC, &amp;Item-&gt;rcItem, CreateSolidBrush(0x6C6C6C) );
                  SetBkMode(Item-&gt;hDC, 0x6C6C6C);
                  SetTextColor(Item-&gt;hDC, RGB(0,0,255));
              }else{
                  FillRect(Item-&gt;hDC, &amp;Item-&gt;rcItem, CreateSolidBrush(0x6C6C6C) );
                  SetBkMode(Item-&gt;hDC, 0x6C6C6C);
                  SetTextColor(Item-&gt;hDC, RGB(255,255,255));
              }
                  int len;
                  len = GetWindowTextLength(Item-&gt;hwndItem);
                  LPSTR lpBuff;
                  lpBuff = new char[len+1];
                  GetWindowTextA(Item-&gt;hwndItem, lpBuff, len+1);
                  DrawTextA(Item-&gt;hDC, lpBuff, len, &amp;Item-&gt;rcItem, DT_CENTER | DT_VCENTER | DT_WORDBREAK);
          }
  break;
  case WM_COMMAND:
  
              switch ( LOWORD(wParam) ){
                  case 1:
                     buttonPressed[0] = 1;
                     buttonPressed[1] = 0;
                     buttonPressed[2] = 0;
                     buttonPressed[3] = 0;
                  break;
                  case 2:
                      buttonPressed[0] = 0;
                     buttonPressed[1] = 1;
                     buttonPressed[2] = 0;
                     buttonPressed[3] = 0;
                  break;
                  case 3:
                     buttonPressed[0] = 0;
                     buttonPressed[1] = 0;
                     buttonPressed[2] = 1;
                     buttonPressed[3] = 0;
                  break;
                  case 4:
                     buttonPressed[0] = 0;
                     buttonPressed[1] = 0;
                     buttonPressed[2] = 0;
                     buttonPressed[3] = 1;
                  break;
  
              }
  
  break;
  </code></pre>