c - InvalidateRect() 是否向子控件发送 WM_PAINT 消息?

标签 c winapi

如果我在父窗口上调用 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/

相关文章:

delphi - 从内部 .dll 获取模块句柄

c++ - 在Windows下杀死所有未列入白名单的进程

MYSQL_ROW 和 row[0] 转字符串类型?

c - fefo 在 while 循环的最后一次迭代期间不检查 EOF?

c++ - 在不移动末尾的情况下删除文件中间的字节?

c# - FindWindowEx 在子对话窗口

c++ - 逐字符读取标准输入 C++

c++ - 句柄无效(使用应用程序验证程序)

C 为什么 scanf 返回错误输出

C - 使用 strncpy() 函数后的随机字符