title: Tic Tac Toe: Winapi painting
body: <p>I am having trouble painting in my client area whenever I turn a bool true, trying to make a Tic Tac Toe, and once I get the initial painting properly I can keep going.</p>
  
  <p>The main problem is that it is not painting the lower rows properly, or they are painted after a 3 or 4 click, At the moment I don't care about circles, just want to know what I am  have wrong.</p>
  
  <pre><code>LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  {
          static BOOL fState[DIVISIONS][DIVISIONS];
          bool  XorO = false;
          static int  cxBlock, cyBlock;`
  
          HDC         hdc;
          int         x, y, iPosX , iPosY;
          PAINTSTRUCT ps;
          RECT        rect;
  
          static const int grid = 1000;
          static const int block = grid / DIVISIONS;
          static const int width = 1200;
          static const int height =1200;
  
          switch (message)
          {
          case WM_SIZE:
  
                  cxBlock = LOWORD (lParam) / DIVISIONS ;
                  cyBlock = HIWORD (lParam) / DIVISIONS ;
  
              return 0;
  
          case WM_LBUTTONDOWN:
              x = LOWORD(lParam)/ cxBlock;
              y = HIWORD(lParam)/cyBlock;
  
              if (x &lt; DIVISIONS &amp;&amp; y &lt; DIVISIONS)
              {
                  //Click in the first cuadrant x = 0 and y = 0 , so both false
                  //second x = 1, y = 0
                  //third x 2 , y = 0 and so on.
                  fState[x][y] ^= 1;
                  rect.left = x * block;
                  rect.top = y * block;
                  rect.right = (x + 1) * block;
                  rect.bottom = (y + 1) * block;
  
                  InvalidateRect(hwnd, &amp;rect, FALSE);
  
              }
              else
                  MessageBeep(0); 
  
              return 0;
  
          case WM_PAINT:
  
              hdc = BeginPaint(hwnd, &amp;ps);
  
  
              //paint X or ellipses here
              for (x = 0; x &lt; DIVISIONS; x++)
                  for (y = 0; y &lt; DIVISIONS; y++)
                  {
  
                      if (fState[x][y] )
                      {
                          MoveToEx(hdc, x     * block, y       *  block, NULL);
                          LineTo(hdc,  (x + 1) * block, (y + 1) *  block);
                          MoveToEx(hdc, x     * block, (y + 1) *  block, NULL);
                          LineTo(hdc,  (x + 1) * block, y       *  block);
                      }
                  }
  
  
              //main grid
              for (int i = block; i &lt; grid - 1; i += block) {
                  MoveToEx(hdc, i, 0, NULL); 
                  LineTo(hdc, i, grid);
                  MoveToEx(hdc, 0, i, NULL);
                  LineTo(hdc, grid, i);
  
  
              }
  
              EndPaint(hwnd, &amp;ps);
              return 0;
  
          case WM_DESTROY:
              PostQuitMessage(0);
              return 0;
          }
          return DefWindowProc(hwnd, message, wParam, lParam);
      }
  </code></pre>
  
  <p>I even tried to make the painting more direct and primitive by making a single if statement for each scenario but, once the program runs , it does not paint correctly on the second and third line. or if I click space 2,2 (the last one on the grid) it does not paint until i click somewhere else...</p>