title: How to keep aero glass when handling WM_NCPAINT WinEvent
body: <p>I’m handling the WM_NCPAINT WinEvent for draw a pushbutton at the non client area of my window. But as you can see at the following image, the aero glass border has disappeared, and my window has no border. So I've found this answer: <a href="https://stackoverflow.com/questions/1146365/handling-wm-ncpaint-breaks-dwm-glass-rendering-on-vista-aero">Handling WM_NCPAINT &quot;breaks&quot; DWM glass rendering on Vista/Aero</a> and I’ve tried to apply the solution proposed on that page on my project with no result. What I’m doing wrong?</p>
  
  <p>Screenshot of my window:</p>
  
  <p><img src="https://i.stack.imgur.com/oQlXF.jpg" alt="enter image description here"></p>
  
  <p>On my .pro file I’ve added:</p>
  
  <pre><code>LIBS += -lGdi32
  LIBS += -lUser32
  LIBS += -lDwmApi
  LIBS += -lUxTheme
  </code></pre>
  
  <p>And here my code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;dwmapi.h&gt;
  #include &lt;Uxtheme.h&gt;
  #include &lt;tmschema.h&gt;
  #include &lt;Strsafe.h&gt;
  #include &lt;limits.h&gt;
  
  HTHEME m_htheme;
  
  bool MainWindow::winEvent(MSG *pMessage, long *result)
  {
      UINT m = pMessage-&gt;message;
      if(m == WM_NCPAINT || m == WM_ACTIVATE)
      {
          draw();
          return true;
      }
      return QWidget::winEvent(pMessage, result);
  }
  
  void MainWindow::draw()
  {
      HWND id = winId();
  
      DWMNCRENDERINGPOLICY policy = DWMNCRP_ENABLED;
      HRESULT hr = DwmSetWindowAttribute(id, DWMWA_NCRENDERING_POLICY, (void*)&amp;policy, sizeof(DWMNCRENDERINGPOLICY));
  
      if(SUCCEEDED(hr))
      {
          m_htheme = OpenThemeData(id, L"Button");
          if (m_htheme)
          {
              HDC hDeviceContext = GetWindowDC(id);
              RECT rc = {10, 10, 100, 32};
              RECT rcContent;
  
              LPCWSTR caption = TEXT("text");
              size_t cch;
              StringCchLength(caption, MAX_PATH, &amp;cch);
  
              hr = DrawThemeBackground(m_htheme, hDeviceContext, BP_PUSHBUTTON, CBS_NORMAL, &amp;rc, 0);
  
              if (SUCCEEDED(hr))
                  hr = GetThemeBackgroundContentRect(m_htheme, hDeviceContext, BP_PUSHBUTTON,
                                                     CBS_NORMAL, &amp;rc, &amp;rcContent);
  
              if (SUCCEEDED(hr))
                  hr = DrawThemeText(m_htheme, hDeviceContext, BP_PUSHBUTTON, CBS_NORMAL,
                                     caption, cch, DT_CENTER | DT_VCENTER | DT_SINGLELINE, 0, &amp;rcContent);
          }
      }
  }
  </code></pre>