Available in LEADTOOLS Imaging Pro, Vector, Document, and Medical Imaging toolkits. |
Double buffering is used to reduce flickering when painting windows. In many cases, double buffering is entirely unnecessary, but there are some instances where it can improve the appearance of your application.
For example, there are certain situations when using annotations that "flickering" is very difficult to avoid. One such situation occurs when zooming in very quickly on an annotation. To see this, perform the following steps:
1. |
Run the main Class library annotation demo (either clanno32.exe for the Microsoft platform, or BCLAnnot.exe for the Borland platform) |
2. |
Load an image |
3. |
Draw a button annotation |
4. |
In the View menu, disable double buffering |
5. |
Hold the "+" key to zoom in very quickly |
Note that you can very clearly see the image being painted, and then the annotation over the image. For a fraction of a second, you can see the image under the annotation.
Now enable the double buffering option, and begin zooming. Notice how there is no flickering.
You can very easily add double buffering to your applications by using the following functions.
LDoubleBuffer::EnableDoubleBuffer
To use double buffering, first you must create a double buffer handle using LDoubleBuffer::CreateHandle. The double buffer handle is an argument for all of the double buffering functions.
Next you must decide which paint operations will be double buffered. All such paint operations must be wrapped in LDoubleBuffer::Begin and LDoubleBuffer::End calls.
The LDoubleBuffer::Begin call returns a memory hDC. All subsequent paint operations should use this hDC for painting. To render the contents of the memory hDC, call LDoubleBuffer::End.
The LDoubleBuffer::Begin and LDoubleBuffer::End calls intelligently manage an internal memory hDC. The memory hDC is only reallocated when necessary.
At any time in your application, you can easily enable/disable the double buffering by calling LDoubleBuffer::EnableDoubleBuffer with appropriate arguments. When the double buffering is disabled, all wrapped paint calls paint directly to the screen. When double buffering is enabled, paints are triggered only by calls to LDoubleBuffer::End.
When you are finished double buffering, call LDoubleBuffer::DestroyHandle to free the internally allocated resources.