title: Issues with handling ON_WM_NCPAINT() message and OnNCPaint() override. (Overriding default MFC window border) [2020]
body: <p>I'm attempting to create a &quot;dark mode&quot; theme for my Windows app, and I'm experiencing some inconsistencies with overriding the OnNcPaint() function. Please pardon the giant red box. I'm only coloring it in that way to show the issue.</p>
  <p>Here's my initial function:</p>
  <pre><code>void CSoftwareDlg::OnNcPaint() {
      Default(); //I can also use &quot;CDialgoEx::OnNcPaint();&quot; here for the same result because it just calls &quot;Default...&quot;
  
      CDC* pDC = GetWindowDC();
      CRect rect;
      GetWindowRect(&amp;rect);
      rect.top = 0;
      rect.left = 0;
      rect.bottom = rect.Size().cy;
      rect.right = rect.Size().cx;
      pDC-&gt;FillRect(rect, &amp;m_brushRed);
      
      ReleaseDC(pDC);
  }
  </code></pre>
  <p>And the (usual) result:
  <a href="https://i.stack.imgur.com/i1jDI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i1jDI.png" alt="with Default" /></a></p>
  <p>I can partially resolve this issue by removing the call to <code>Default();</code>:
  <a href="https://i.stack.imgur.com/VjMfM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VjMfM.png" alt="without Default" /></a></p>
  <p>...But anytime the window is moved(or redrawn I guess):
  <a href="https://i.stack.imgur.com/WgBB5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WgBB5.png" alt="border redraws itself" /></a></p>
  <p>I can also add a <code>Sleep(1000);</code> to achieve somewhat different results, but it's not worth posting a picture. Ultimately... My override isn't really &quot;overriding&quot; as it should based on the numerous pieces of sample code I've taken a look at. I know that <code>Default();</code> is some kind of threaded callback function, but I have no idea how to troubleshoot this issue any further.</p>
  <p>Do I need to perform some kind of wait for the <code>Default();</code> command? Do I need to implement <code>OnNcPaint()</code> as some kind of callback function? Are there additional functions I need to be overriding?</p>