Reputation:
If I called InvalidateRect()
on the parent Window, for example:
InvalidateRect(hWnd, NULL, TRUE);
What will happen is that inside the WM_PAINT
handler, BeginPaint()
will send a WM_ERASEBKGND
message, which will erase the background, and hence all child controls will disappear.
But the child controls remain when I call InvalidateRect()
, so does that means InvalidateRect()
also sends WM_PAINT
messages to the child controls also?
Upvotes: 1
Views: 1771
Reputation: 50046
Does InvalidateRect() sends WM_PAINT messages to the child controls?
yes (mostly), its quite clearly described here:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd183426(v=vs.85).aspx
The system sets the update region for a child window whenever part of the parent window's update region includes a portion of the child window. In such cases, the system first sends a WM_PAINT message to the parent window and then sends a message to the child window, allowing the child to restore any portions of the window that the parent may have drawn over.
but with exception:
an application cannot generate a WM_PAINT message for the child by invalidating a portion of the parent's client area that lies entirely under the child window. In such cases, neither window receives a WM_PAINT message.
which is actually interesting to know
You can prevent redraw of child windows by setting WS_CLIPCHILDREN to parent window, or by invalidating redraw with the use of RedrawWindow function with RDW_NOCHILDREN flag.
Upvotes: 1