title: Creating a transparent window in C++ Win32
body: <p>I'm creating what should be a very simple Win32 C++ app whose sole purpose it to ONLY display a semi-transparent PNG. The window shouldn't have any chrome, and all the opacity should be controlled in the PNG itself.</p>
  <p>My problem is that the window doesn't repaint when the content under the window changes, so the transparent areas of the PNG are &quot;stuck&quot; with what was under the window when the application was initially started.</p>
  <p>Here's the line where I setup the new window:</p>
  <pre><code>hWnd = CreateWindowEx(WS_EX_TOPMOST, szWindowClass, szTitle, WS_POPUP, 0, height/2 - 20, 40, 102, NULL, NULL, hInstance, 0);
  </code></pre>
  <p>For the call to RegisterClassEx, I have this set for the background:</p>
  <pre><code>wcex.hbrBackground = (HBRUSH)0;
  </code></pre>
  <p>Here is my handler for WM_PAINT message:</p>
  <pre><code> case WM_PAINT:
   {
     hdc = BeginPaint(hWnd, &amp;ps);
     Gdiplus::Graphics graphics(hdc);
     graphics.DrawImage(*m_pBitmap, 0, 0);
     EndPaint(hWnd, &amp;ps);
     break;
   }
  </code></pre>
  <p>One thing to note is that the application is always docked to the left of the screen and doesn't move. But, what's underneath the application may change as the user opens, closes or moves windows under it.</p>
  <p>When the application first starts, it looks perfect. The transparent (and simi-transparent) parts of the PNG show through perfectly. BUT, when the background underneath the application changes, the background DOESN'T update, it just stays the same from when the application first started. In fact, WM_PAINT (or WM_ERASEBKGND does not get called when the background changes).</p>
  <p>I've been playing with this for quite a while and have gotten close to getting 100% right, but not quite there. For instance, I've tried setting the background to (HBRUSH) NULL_BRUSH and I've tried handling WM_ERASEBKGND.</p>
  <p>What can be done to get the window to repaint when the contents under it changes?</p>