Avoiding flickering

I'm using C++ Builder. I'm using an Image component to paint a background jpg image. So this component has an 'alClient' align and fills the entire form. The form has other visual components, let's just imagine a smaller Image component. The problem is that when I paint something in the smaller image, the background image is also repainted, even if the position and size of the smaller image have not changed, causing the annoying flickering. How can I avoid the background image to be repainted every single time the smaller image changes?
Without knowing too much about this component of yours, I can tell you to search the web for double buffering.
If you're using Windows (which is likely, given you're using 'Builder), and your smaller image component is rectangular, you might be able to tighten up the region that is invalidated. If the image component is well-behaved, that should do the trick.

Otherwise, you need the double buffering approach that webJose mentioned.

Both MFC and ATL provide support for double-buffer drawing, so I would hope that the library provided with C++ Builder would do so, too.

In WIN32 terms, you need to modify the paint proceedure to use an off-screen (memory) DC for all its drawing and then blit the result to the screen. You also have to disable the background erase call (if you haven't already done so).

Andy
Topic archived. No new replies allowed.