title: Due to invalid ValidateRgn() childs windows do not get WM_PAINT messages
body: <p>I have window with <code>Button</code> control, to drawing I use <code>Direct2D</code>, important <code>WindowProc</code> fragments:</p>
  <pre class="lang-cpp prettyprint-override"><code>LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  {
  ...
      case WM_CREATE:
          HWND button = CreateWindowExW(0, L&quot;button&quot;, L&quot;Send&quot;, WS_CHILD | WS_VISIBLE, 10, 10, 200, 100, hWnd, CONTROL_ID, desc-&gt;hInstance, 0);
          break;
  
      case WM_PAINT:
          render_target-&gt;BeginDraw();
          ... rendering stuff ...
          HRESULT result = render_target-&gt;EndDraw();
  
          // Validate region:
          ValidateRgn(hWnd, nullptr); // validate entire client area
          break;
  ...
  }
  </code></pre>
  <p>This code doesn't quite work, my child <code>Button</code> was not painted. I suppose it doesn't receive <code>WM_PAINT</code> message because I validated entire window, hence Window don't ask to repaint the same pixels twice.</p>
  <p>So I take that into consideration, and exclude <code>Button</code> region from validation:</p>
  <pre class="lang-cpp prettyprint-override"><code>    // Validate region:
      HRGN update = CreateRectRgn(0, 0, 0, 0);
      HRGN button = CreateRectRgn(10, 10, 210, 110);
  
      GetUpdateRgn(hWnd, update, false); // get update rect
      CombineRgn(update, update, tab, RGN_DIFF); // exclude button region
      ValidateRgn(hWnd, update); // validate window client area (excluding button) to stop receiving WM_MESSAGE
  </code></pre>
  <p>Now <code>Button</code> still is not painted, what's more I receive <code>WM_PAINT</code> in infinite loop, with update region equal <code>Rgn(10, 10, 210, 110)</code>. I expected that after <code>WM_PAINT</code> in  <code>WindowProc</code>, child <code>Button</code> should received it and there missing update region will be validated.</p>
  <hr />
  <p>Everything works if I wrap <code>WM_PAINT</code> message in <code>BeginPaint(hWnd, nullptr)</code> <code>EndPaint(hWnd, nullptr)</code>:</p>
  <pre><code>    case WM_PAINT:
          ::log &lt;&lt; &quot;WINDOW_PAINT_START&quot; &lt;&lt; std::endl;
          BeginPaint(hWnd, nullptr); // use BeginPaint from GDI
  
          render_target-&gt;BeginDraw();
          ... rendering stuff ...
          HRESULT result = render_target-&gt;EndDraw();
  
          // Validate region code is not needed anymore because BeginPaint take care of that.
          EndPaint(hWnd, nullptr);
          ::log &lt;&lt; &quot;WINDOW_PAINT_END&quot; &lt;&lt; std::endl;
          break;
  </code></pre>
  <p>It seems to <code>BeginPaint()</code> validate update region and trigger <code>WM_PAINT</code> for children windows. It should be called in response to <code>WM_PAINT</code> even if you don't use <code>GDI</code> and it's <code>PAINTSTRUCT-&gt;HDC</code>.
  But if <code>BeginPaint()</code> indeed trigger <code>WM_PAINT</code> for children windows then my log calling order should looks like <code>WINDOW_PAINT_START -&gt; BUTTON_PAINT_START -&gt; BUTTON_PAINT_END -&gt; WINDOW_PAINT_END</code>, in fact looks like <code>WINDOW_PAINT_START -&gt; WINDOW_PAINT_END -&gt; BUTTON_PAINT_START -&gt; BUTTON_PAINT_END</code>. So <code>WM_PAINT</code> for <code>Button</code> is delayed until <code>WinProc</code> returns from it's <code>WM_PAINT</code>: hence trigger happen outside, hence children drawing happend after main window paint which is in compliance with MSDN.</p>
  <p>So exactly in which moment <code>WM_PAINT</code> to children windows is dispatched?</p>