title: WinAPI. How to redraw window which has no background?
body: <p>Hi I have <code>WNDCLASSEX</code> structure which has this data:</p>
  
  <pre><code>m_wndClass.cbSize = sizeof(WNDCLASSEX);
  m_wndClass.style = CS_NOCLOSE;
  m_wndClass.lpfnWndProc = WndProc;
  m_wndClass.cbClsExtra = 0;
  m_wndClass.cbWndExtra = 0;
  m_wndClass.hInstance = GetModuleHandle(NULL);
  m_wndClass.hIcon = NULL;
  m_wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  m_wndClass.hbrBackground = NULL;
  m_wndClass.lpszMenuName = NULL;
  m_wndClass.lpszClassName = Checkbox::CHECKBOX_CLASS.c_str(); 
  m_wndClass.hIconSm = NULL;
  </code></pre>
  
  <p>I need to have window without background, because I need to draw text on parent window and text may be any color.</p>
  
  <p>Drawing works fine, code for drawing:</p>
  
  <pre><code>case WM_PAINT:
  {
      PAINTSTRUCT ps;
      HDC dc = BeginPaint(window, &amp;ps);
  
      if (!classInfo-&gt;m_text.empty())
      {
          HDC wdc = GetDC(window);
  
          SetBkMode(wdc,TRANSPARENT);
          DrawText(wdc, classInfo-&gt;m_text.c_str(), -1, &amp;classInfo-&gt;m_textRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOCLIP);
          ReleaseDC(window, wdc); 
      }
  
      EndPaint(window, &amp;ps);
      break;
  }
  </code></pre>
  
  <p>However I have method to change text of label:</p>
  
  <pre><code>void Checkbox::SetText(const String&amp; text)
  {
      m_text = text;
      SetTextRectSize();   //calculates size of RECT 
      if (m_window != NULL)
          InvalidateRect(m_window, NULL, TRUE);
  }
  </code></pre>
  
  <p>After I create window with label I see label, however if I want to change text on it, it doesn't change (I need to manualy resize window and it changes after that). However I hadn't have this problem at the time when I used to have colored background, for example my window class had this:</p>
  
  <pre><code>m_wndClass.hbrBackground = HBRUSH(COLOR_3DFACE+1);
  </code></pre>
  
  <p>I want to ask, how to update window which, has no background.</p>
  
  <p><strong>EDIT:</strong>  I have tried some stuff</p>
  
  <p><code>FillRect(dc, &amp;rect, (HBRUSH)GetStockObject(NULL_BRUSH));</code></p>
  
  <p>also tried to change window procedure:</p>
  
  <pre><code>case WM_CTLCOLORSTATIC:
  {
      HDC hdc = (HDC) wp; 
      SetBkMode (hdc, TRANSPARENT);
      return (LRESULT)GetStockObject(NULL_BRUSH);
  }
  </code></pre>
  
  <p>And the result is that I draw new text on previous, after setting <code>text</code> into <code>some longer text</code> part of label becomes corupted! <a href="http://i.stack.imgur.com/ePt71.png" rel="nofollow"> see this</a> but after resizing the main window my label becomes readable. </p>