windows 在 Win32 上,我可以在一段时间内禁用窗口绘制吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5001566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
On Win32, can I disable painting of a window for a period of time?
提问by sashoalm
Is there a function that will freeze window repainting for some time, while I do changes to the layout of my dialog?
是否有一个功能可以在我更改对话框布局时冻结窗口重绘一段时间?
回答by Cody Gray
If you find that you actually need to do this, you should send the window a WM_SETREDRAW
messagewith the wParam
set to FALSE. This indicates that the window should not be redrawn after its contents are changed.
如果你发现你的实际需要做到这一点,你应该发送窗口中的WM_SETREDRAW
信息与wParam
设置为false。这表示窗口内容更改后不应重新绘制。
When you want to re-enable drawing, send another WM_SETREDRAW
message, this time with the wParam
set to TRUE.
当您想重新启用绘图时,发送另WM_SETREDRAW
一条消息,这次wParam
设置为 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 subjectis a great read.
有关更多信息,请阅读Raymond Chen 关于该主题的博客文章。
回答by avakar
You should do the repositioning in a single swoop; use BeginDeferWindowPoset al.
您应该一次性完成重新定位;使用BeginDeferWindowPos等。
回答by David Heffernan
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.
Windows 绘制的方式是系统发布WM_PAINT
指示您绘制的窗口消息。如果您愿意,您可以在修改布局时选择忽略这些消息,然后在完成修改布局后强制执行绘制循环。
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.
但是,我在 Windows 上编写 UI 的经验是,您通常不需要采取这些步骤。由于您负责泵送消息队列,如果在您修改布局的过程中刷新窗口,那么您一定采取了导致消息队列被泵送的操作。
Put simply, stop pumping the queue whilst modifying the layout and your problems will vanish.
简而言之,在修改布局的同时停止抽水队列,您的问题就会消失。