title: Drawing in the extended frame gives strange colors
body: <p>I have a window with extended frame made like this:</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb688195.aspx" rel="nofollow noreferrer">Custom Window Frame Using DWM</a></p>
  
  <p>But anything drawn in the extended frame has very strange colors (except for white, the only color that stays the same), like this (ignore the messy content in the center and the messy toolbar at the right.</p>
  
  <p><img src="https://i.stack.imgur.com/wZiug.png" alt="Screenshot"></p>
  
  <p>The pink rectangle (<code>0xFFC9FF</code>) was supposed to be <code>0x8000FF</code>. If I put the DirectX11 content (the center thing) in the extended frame, alpha blending for my FPS counter gets messed up. If I do the same to the right dialog, the same happens.</p>
  
  <p><strong>So how can I do this correctly?</strong> I've already tried to draw first to a memory DC and then use <code>BitBlt</code>. I'm using GDI+ (plus <code>CreateCompatibleDC</code>, <code>CreateCompatibleBitmap</code> and other functions to handle the memory DC).</p>
  
  <p>PS: Because you asked, here is <code>WndProc</code>:</p>
  
  <pre><code>LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  {
      LRESULT ReturnValue;
      if (DwmDefWindowProc(hWnd, uMsg, wParam, lParam, &amp;ReturnValue)) return ReturnValue;
  
      switch (uMsg)
      {
      case WM_CREATE:
      {
          // ...
  
          RECT rcClient;
          GetWindowRect(hWnd, &amp;rcClient);
  
          SetWindowPos(hWnd,
              NULL,
              rcClient.left, rcClient.top,
              rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
              SWP_FRAMECHANGED);
  
          return 0;
      }
      case WM_ACTIVATE:
      {
          MARGINS Margins;
          Margins.cxLeftWidth = LEFT_BORDER;
          Margins.cxRightWidth = RIGHT_BORDER;
          Margins.cyTopHeight = TOP_BORDER;
          Margins.cyBottomHeight = BOTTOM_BORDER;
          if (DwmExtendFrameIntoClientArea(hWnd, &amp;Margins) != S_OK)
          {
              MessageBox(hWnd, L"Erro ao configurar janela.", NULL, MB_ICONERROR);
              PostQuitMessage(WM_QUIT);
          }
  
          if (LOWORD(wParam))
          {
              fActive = true;
          }
          else
          {
              fActive = false;
          }
          InvalidateRect(hWnd, NULL, false);
  
          return 0;
      }
  
      case WM_SIZE:
          /* ... */
  
      case WM_NCCALCSIZE:
          return 0;
  
      case WM_NCHITTEST:
          /* ... */
  
      case WM_GETMINMAXINFO:
          ((LPMINMAXINFO)lParam)-&gt;ptMinTrackSize = { 640, 400 };
          return 0;
  
      case WM_PAINT:
      {
          using namespace Gdiplus;
  
          PAINTSTRUCT ps;
          HDC hDC = BeginPaint(hWnd, &amp;ps);
  
          RECT rcWindow;
          GetWindowRect(hWnd, &amp;rcWindow);
          POINT ptSize = { rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top };
  
          HDC hBuffer = CreateCompatibleDC(hDC);
          HBITMAP hBitmap = CreateCompatibleBitmap(hDC, ptSize.x, ptSize.y);
          SelectObject(hBuffer, hBitmap);
  
          Graphics graphics(hBuffer);
          Pen Outline(Color(128, 128, 128));
          SolidBrush Selected(Color(128, 0, 255));
          Rect Tab1(10, 10, 200, 50);
  
          graphics.FillRectangle(&amp;Selected, Tab1);
          graphics.DrawRectangle(&amp;Outline, Tab1);
  
          /* ... */
  
          BitBlt(hDC, 0, 0, ptSize.x, ptSize.y, hBuffer, 0, 0, SRCCOPY);
  
          EndPaint(hWnd, &amp;ps);
          return 0;
      }
  
      /* ... */
  
      default:
          return DefWindowProc(hWnd, uMsg, wParam, lParam);
      }
  }
  </code></pre>