在 Win32 上,我可以在一段时间内禁用窗口绘制吗?

发布于 2024-10-17 10:55:03 字数 40 浏览 9 评论 0原文

当我更改对话框的布局时,是否有一个函数可以将窗口重绘冻结一段时间?

Is there a function that will freeze window repainting for some time, while I do changes to the layout of my dialog?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神仙妹妹 2024-10-24 10:55:03

如果您发现确实需要执行此操作,则应向窗口发送 WM_SETREDRAW 消息,其中 wParam 设置为 FALSE。这表明窗口的内容更改后不应重新绘制。

当您想要重新启用绘图时,请发送另一条 WM_SETREDRAW 消息,这次将 wParam 设置为 TRUE。

示例代码:

// Disable window updates
SendMessage(hWnd, WM_SETREDRAW, FALSE, 0);

// Perform your layout here
// ...

// Re-enable window updates
SendMessage(hWnd, WM_SETREDRAW, TRUE, 0);

有关详细信息,请参阅 Raymond Chen 的博客文章主题是一本很棒的读物。

If you find that you actually need to do this, you should send the window a WM_SETREDRAW message with the wParam set to FALSE. This indicates that the window should not be redrawn after its contents are changed.

When you want to re-enable drawing, send another WM_SETREDRAW message, this time with the wParam set to TRUE.

Sample code:

// Disable window updates
SendMessage(hWnd, WM_SETREDRAW, FALSE, 0);

// Perform your layout here
// ...

// Re-enable window updates
SendMessage(hWnd, WM_SETREDRAW, TRUE, 0);

For more information, Raymond Chen's blog article on the subject is a great read.

白馒头 2024-10-24 10:55:03

你应该一下子就重新定位;使用 BeginDeferWindowPos 等。

You should do the repositioning in a single swoop; use BeginDeferWindowPos et al.

梦行七里 2024-10-24 10:55:03

Windows 绘制的方式是系统发布窗口 WM_PAINT 消息来指示您绘制。如果您愿意,您可以在修改布局时选择忽略这些消息,然后在完成修改布局后强制执行绘制周期。

然而,我在 Windows 上编写 UI 的经验是,通常不需要采取这样的步骤。由于您负责泵送消息队列,因此如果在您修改布局时刷新窗口,那么您一定已经采取了导致消息队列泵送的操作。

简而言之,在修改布局的同时停止增加队列,您的问题就会消失。

The way Windows paints is that the system posts your window WM_PAINT messages instructing you to paint. You can elect to ignore these messages if you so wish, whilst you are modifying the layout, and then force a paint cycle once you have finished modifying the layout.

However, my experience of writing UI on Windows is that you usually don't need to take such steps. Since you are in charge of pumping your message queue, if the window is being refreshed whilst you are in the middle of modifying the layout, then you must have taken action that led to the message queue being pumped.

Put simply, stop pumping the queue whilst modifying the layout and your problems will vanish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文