title: C/C++ : Update text using DrawText with winapi
body: <p>I am writing a simple windows application, in which I want to display to the user two variables : NC and NL.
  When a certain action is done by the user, NC and NL are updated (response to WM_COMMAND)</p>
  
  <p>So I am using DrawText in response to WM_PAINT message to display these values. Unfortunately, when the values changes, the message won't update, whereas WM_PAINT is effectively called again. (checked and re-checked)</p>
  
  <p>I want to precise that I also tried with TextOut, but the updated text overlapped on the old text, even if I cleared the screen. I also tried to update the text directly in response to WM_COMMAND, without better success. I didn't find any valuable help on the Internet nor in Windows help.</p>
  
  <p>Isolated the problem in a blank project, I cannot identify the problem. Here is a piece of code.</p>
  
  <pre><code>    case WM_PAINT:
      //writeText(mainWnd, "                                ", RGB(0, 25, 255), 410, 10);
  
      //writeText(mainWnd, buff, RGB(0, 25, 255), 410, 10);
      //sprintf(buff, "piece : %s", isCaval ? "cavalier" : "roi");
      //writeText(mainWnd, buff, RGB(0, 255, 25), 410, 40);
  {
  
      static char buff[250] = { '\0' };
      sprintf(buff, "board : %d x %d", NC, NL);
      static PAINTSTRUCT ps;
      static HDC hDC = BeginPaint(mainWnd, &amp;ps);
      static RECT rect = { 250,250,400,400 };
      SetTextColor(hDC, RGB(255, 0, 0));
  
      //SetBkMode(hDC, TRANSPARENT);
      DrawText(hDC, buff, strlen(buff), &amp;rect, DT_CENTER);
      EndPaint(mainWnd, &amp;ps);
  }
  </code></pre>
  
  <p>How on earth can I get the displayed text succesfully updating as soon as NC or NL changes ? </p>