Windows(或其他操作系统)如何更新客户端的后台区域?
或者换个方式问,OnEraseBkgnd() 是如何工作的?
我正在构建一个自定义控件,并且遇到了这个问题。
孩子像往常一样是矩形。 我必须禁用 OnEraseBkgnd(),并且只使用 OnPaint()。
我需要的是有效地清除孩子后面的区域并且不闪烁。< br>
使用后台缓冲区等技术不是一种选择。
编辑:我对 OnEraseBkgnd 背后的算法非常感兴趣()。 但任何有帮助的答案也将被接受。
Or to ask it another way, how OnEraseBkgnd() works?
I'm building a custom control and I hit on this problem.
Childs are rectangles, as usual. I had to disable OnEraseBkgnd() and I use only the OnPaint().
What I need is to efficiently clear the area behind the childs and without flickering.
Techniques like using back buffers are not an option.
Edit: I am very interested in the algorithm that's under the hood of OnEraseBkgnd(). But any helpful answer will also be accepted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常在 Windows 中,减少闪烁的最简单(但不是最有效)的方法是关闭
WM_ERASEBKGND
通知处理。 这是因为,如果您在通知处理程序中擦除背景,然后在 WM_PAINT 处理程序中绘制窗口,则两者之间会有短暂的延迟 - 此延迟被视为闪烁。相反,如果您在
WM_PAINT
处理程序中执行所有擦除和绘制操作,您会看到更少的闪烁。 这是因为两者之间的延迟减少了。 您仍然会看到一些闪烁,特别是在调整大小时,因为两个操作之间仍然存在很小的延迟,并且您无法始终在显示器下一次出现垂直消隐中断之前进入所有绘图。 如果您无法使用双缓冲,那么这可能是您能够使用的最有效的方法。通过遵循有关客户区失效的大多数常见建议,您可以获得更好的绘图性能 - 除非确实需要,否则不要使整个窗口失效。 尝试仅使已更改的区域无效。 另外,如果您要同时更新子窗口集合的位置,则应该使用
BeginDeferWindowPos
函数。Usually in Windows, the easiest (but not most effective) means of reducing flicker, is to turn off the
WM_ERASEBKGND
notification handling. This is because if you erase the background in the notification handler, then paint the window in theWM_PAINT
handler, there is a short delay between the two - this delay is seen as a flicker.Instead, if you do all of the erasing and drawing in the
WM_PAINT
handler, you will tend to see a lot less flicker. This is because the delay between the two is reduced. You will still see some flicker, especially when resizing because there is still a small delay between the two actions, and you cannot always get in all of the drawing before the next occurance of the vertical blanking interrupt for the monitor. If you cannot use double buffering, then this is probably the most effective method you will be able to use.You can get better drawing performance by following most of the usual recommendations around client area invalidation - do not invalidate the whole window unless you really need to. Try to invalidate only the areas that have changed. Also, you should use the
BeginDeferWindowPos
functions if you are updating the positions of a collection of child windows at the same time.