如果我在父窗口上调用 InvalidateRect()
,例如:
InvalidateRect(hWnd, NULL, TRUE);
将会发生的是,在 WM_PAINT
处理程序中,BeginPaint()
将发送一条 WM_ERASEBKGND
消息,该消息将删除背景,并且因此所有子控件都会消失。
但是当我调用 InvalidateRect()
时,子控件仍然保留,这是否意味着 InvalidateRect()
也会向子控件发送 WM_PAINT
消息还可以控制吗?
最佳答案
Does InvalidateRect() sends WM_PAINT messages to the child controls?
是的(大部分),这里描述得很清楚:
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.
但有异常(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.
这实际上很有趣
您可以通过将 WS_CLIPCHILDREN 设置为父窗口来防止子窗口重绘,或者通过使用带有 RDW_NOCHILDREN 标志的 RedrawWindow 函数使重绘无效。
关于c - InvalidateRect() 是否向子控件发送 WM_PAINT 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32371075/