WinAPI Double-buffering

落花浮王杯 提交于 2019-12-04 13:42:29

问题


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?


回答1:


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.




回答2:


Take a look at the following article: Flicker-Free Displays Using an Off-Screen DC.

This article describes a technique for drawing to a window device context (DC) in such a way that the screen does not flicker. The technique is very simple and easy to implement.

I learnt how to prevent flickering from this tutorial several years ago.



来源:https://stackoverflow.com/questions/3895305/winapi-double-buffering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!