WinAPI 双缓冲
默认的 winAPI 应用程序没有双缓冲。相反,它在确保只绘制需要绘制的内容方面做得非常非常好,这使其具有无缝的外观。但是,当您调整窗口大小时,需要重新绘制整个窗口,这会导致控件、选项卡上的背景以及有时选项卡的白色之间闪烁。
所以我的问题是,在我的应用程序中支持双缓冲的最简单方法是什么?
A default winAPI application does not have double-buffering. Instead, it does a very, very good job of ensuring that only what needs to be drawn is drawn, and that gives it a seamless appearance. However, when you resize the window, the entire thing needs to be redrawn, and this causes flickering between the controls, the background on the tab, and sometimes the white of the tab.
So my question is, what is the easiest way to support double buffering in my application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个与窗口大小相同的位图,渲染到该位图中,完成后将其传输回窗口。
您可以在现有代码中进行非常直接的就地替换。不要使用渲染到窗口中的设备上下文,而是使用渲染到位图中的设备上下文,并且仅使用原始 DC 将位图传回。
请务必保留位图 - 不要在每次绘制调用中创建它。您只需要在调整窗口大小时重新创建它。
Create a bitmap the size of the window, render into that bitmap, and blit that back into the window when you're done.
You can do a pretty straight-forward in-place replacement in your existing code. Instead of using a device context that renders into the window, use one that renders into the bitmap, and only use the original DC to blit the bitmap back.
Be sure to keep the bitmap around - don't create it in every paint call. You just need to recreate it when the window is resized.
请查看以下文章:使用离屏 DC 实现无闪烁显示器。
几年前,我从本教程中学会了如何防止闪烁。
Take a look at the following article: Flicker-Free Displays Using an Off-Screen DC.
I learnt how to prevent flickering from this tutorial several years ago.