在 Win32 上,我可以在一段时间内禁用窗口绘制吗?
当我更改对话框的布局时,是否有一个函数可以将窗口重绘冻结一段时间?
Is there a function that will freeze window repainting for some time, while I do changes to the layout of my dialog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您发现确实需要执行此操作,则应向窗口发送
WM_SETREDRAW
消息,其中wParam
设置为 FALSE。这表明窗口的内容更改后不应重新绘制。当您想要重新启用绘图时,请发送另一条
WM_SETREDRAW
消息,这次将wParam
设置为 TRUE。示例代码:
有关详细信息,请参阅 Raymond Chen 的博客文章主题是一本很棒的读物。
If you find that you actually need to do this, you should send the window a
WM_SETREDRAW
message with thewParam
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 thewParam
set to TRUE.Sample code:
For more information, Raymond Chen's blog article on the subject is a great read.
你应该一下子就重新定位;使用 BeginDeferWindowPos 等。
You should do the repositioning in a single swoop; use BeginDeferWindowPos et al.
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.