Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinAPI Double-buffering

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?

like image 954
Alexander Rafferty Avatar asked Dec 28 '22 06:12

Alexander Rafferty


2 Answers

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.

like image 118
EboMike Avatar answered Dec 30 '22 19:12

EboMike


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.

like image 21
Bill Avatar answered Dec 30 '22 20:12

Bill