title: Why is my DwmExtendFrameIntoClientArea()'d window not drawing the DWM borders?
body: <p>I've been following <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb688195(v=vs.85).aspx" rel="nofollow noreferrer">MSDN's guide to using the DWM API to extend the frame into the client area</a>, but redone so I can experiment with it once I have something working.</p>
  
  <p>However, when I build it, using <code>cl wincompositiontest.cpp</code> in the Visual Studio 2013 x64 Native Tools Command Line, the program does not draw the window borders. The standard window buttons do work: I can see the Windows 7 button glow and tooltips, and clicking on the buttons does their respective action (so I can close this window). But nothing else works: I can't move or resize the window with the edges, and the borders don't draw, instead drawing white:</p>
  
  <p><img src="https://i.imgur.com/A7xTaWs.png?1" alt="Window"></p>
  
  <p><code>DwmExtendFrameIntoClientArea()</code> returns <code>S_OK</code>.</p>
  
  <p>What's going on? This is on Windows 7 x64 running in VirtualBox; I gave the code to a friend also running Windows 7 on real hardware and they get the same results. Thanks.</p>
  
  <pre><code>// 12 december 2016
  #define UNICODE
  #define _UNICODE
  #define STRICT
  #define STRICT_TYPED_ITEMIDS
  // get Windows version right; right now Windows Vista
  // unless otherwise stated, all values from Microsoft's sdkddkver.h
  // TODO is all of this necessary? how is NTDDI_VERSION used?
  // TODO plaform update sp2
  #define WINVER          0x0600  /* from Microsoft's winnls.h */
  #define _WIN32_WINNT        0x0600
  #define _WIN32_WINDOWS  0x0600  /* from Microsoft's pdh.h */
  #define _WIN32_IE           0x0700
  #define NTDDI_VERSION       0x06000000
  #include &lt;windows.h&gt;
  #include &lt;commctrl.h&gt;
  #include &lt;uxtheme.h&gt;
  #include &lt;windowsx.h&gt;
  #include &lt;shobjidl.h&gt;
  #include &lt;d2d1.h&gt;
  #include &lt;d2d1helper.h&gt;
  #include &lt;dwrite.h&gt;
  #include &lt;usp10.h&gt;
  #include &lt;msctf.h&gt;
  #include &lt;textstor.h&gt;
  #include &lt;olectl.h&gt;
  #include &lt;shlwapi.h&gt;
  #include &lt;dwmapi.h&gt;
  #include &lt;stddef.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;string.h&gt;
  #include &lt;wchar.h&gt;
  #include &lt;stdarg.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;float.h&gt;
  #include &lt;inttypes.h&gt;
  #include &lt;vector&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  
  #pragma comment(linker, \
      "\"/manifestdependency:type='Win32' " \
      "name='Microsoft.Windows.Common-Controls' " \
      "version='6.0.0.0' " \
      "processorArchitecture='*' " \
      "publicKeyToken='6595b64144ccf1df' " \
      "language='*'\"")
  #pragma comment(lib, "user32.lib")
  #pragma comment(lib, "kernel32.lib")
  #pragma comment(lib, "gdi32.lib")
  #pragma comment(lib, "comctl32.lib")
  #pragma comment(lib, "uxtheme.lib")
  #pragma comment(lib, "dwmapi.lib")
  
  #define HR(call) printf("%s -&gt; 0x%I32X\n", #call, call)
  
  LRESULT CALLBACK wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  {
      RECT r;
      MARGINS margins;
      BOOL dwmHandled;
      LRESULT lResult;
  
      dwmHandled = DwmDefWindowProc(hwnd, uMsg, wParam, lParam, &amp;lResult);
      switch (uMsg) {
      case WM_CREATE:
          GetWindowRect(hwnd, &amp;r);
          SetWindowPos(hwnd, NULL,
              r.left, r.top,
              r.right - r.left, r.bottom - r.top,
              SWP_FRAMECHANGED);
          // TODO if we pass SWP_NOOWNERZORDER || SWP_NOZORDER, the default frame is not correctly inhibited
          break;
      case WM_ACTIVATE:
          margins.cxLeftWidth = 8;
          margins.cxRightWidth = 8;
          margins.cyBottomHeight = 20;
          margins.cyTopHeight = 27;
          HR(DwmExtendFrameIntoClientArea(hwnd, &amp;margins));
          break;
      case WM_NCCALCSIZE:
          if (wParam != (WPARAM) FALSE)
              return 0;
          break;
      case WM_CLOSE:
          PostQuitMessage(0);
          break;
      }
      if (dwmHandled)
          return lResult;
      return DefWindowProcW(hwnd, uMsg, wParam, lParam);
  }
  
  int main(void)
  {
      WNDCLASSW wc;
      HWND mainwin;
      MSG msg;
  
      ZeroMemory(&amp;wc, sizeof (WNDCLASSW));
      wc.lpszClassName = L"mainwin";
      wc.lpfnWndProc = wndproc;
      wc.hInstance = GetModuleHandle(NULL);
      wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
      wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
      RegisterClassW(&amp;wc);
  
      mainwin = CreateWindowExW(0,
          L"mainwin", L"Main Window",
          WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, CW_USEDEFAULT,
          400, 400,
          NULL, NULL, GetModuleHandle(NULL), NULL);
  
      ShowWindow(mainwin, SW_SHOWDEFAULT);
      UpdateWindow(mainwin);
  
      while (GetMessageW(&amp;msg, NULL, 0, 0)) {
          TranslateMessage(&amp;msg);
          DispatchMessageW(&amp;msg);
      }
      return 0;
  }
  </code></pre>