Displays the double buffered paint operations.
#include "ltwrappr.h"
virtual L_INT LDoubleBuffer::End(hDC)
Handle to the original target device context
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Use LDoubleBuffer::End when ready to paint all that has been double-buffered to the target hDC. All double buffered paint operations should be wrapped in LDoubleBuffer::Begin and LDoubleBuffer::End calls.
The hDC argument is the device context that you want to double buffer, which in this case should be the same as the hDC argument that was passed to LDoubleBuffer::Begin.
Note that you must create a double buffer handle with LDoubleBuffer::CreateHandle before calling this function.
For more information, see the topic Minimizing Flicker with Double Buffering.
Win32, x64.
This sample illustrates double buffering by bouncing a ball around
a window that contains an image
For simplicity, we assume both the window the hDC are 24 bit
Run the example twice --
L_INT LDoubleBuffer__EndExample(HWND hWnd, L_TCHAR *pszFile, L_BOOL bDoubleBuffer)
{
HBRUSH hBrush;
LBitmap Bitmap;
LDoubleBuffer LDoubleBufferObj;
L_INT cx, cy;
HDC hDC, hMemDC;
RECT rcClient;
RECT rcBitmap;
RECT rcBall;
L_INT dx, dy;
L_INT i;
L_INT nRet;
nRet = Bitmap.Load(pszFile, 0, ORDER_BGRORGRAY, NULL, NULL);
if (nRet != SUCCESS)
{
MessageBox(hWnd, TEXT("Failed to load image"), TEXT("Error"), MB_OK);
return nRet;
}
hBrush = CreateSolidBrush( RGB(100,100,100));
LDoubleBufferObj.CreateHandle();
LDoubleBufferObj.EnableDoubleBuffer(bDoubleBuffer);
GetClientRect(hWnd, &rcClient);
cx = rcClient.right - rcClient.left;
cy = rcClient.bottom - rcClient.top;
hDC = GetDC(hWnd);
rcBitmap.left = 0;
rcBitmap.top = 0;
rcBitmap.right = Bitmap.GetHeight();
rcBitmap.bottom = Bitmap.GetWidth();
SetRect(&rcBall, 0, 0, 75, 75);
dx = dy = 1;
for (i=0; i<2000; i++)
{
// Double buffer painting the image and the moving ball
hMemDC = LDoubleBufferObj.Begin(hDC, cx, cy);
FillRect(hMemDC, &rcClient, hBrush);
nRet = Bitmap.SetDstRect(&rcBitmap);
if(nRet != SUCCESS)
return nRet;
LPaint MyPaint(&Bitmap, hMemDC);
nRet = MyPaint.PaintDC();
if(nRet != SUCCESS)
return nRet;
Ellipse(hMemDC, rcBall.left, rcBall.top, rcBall.right, rcBall.bottom);
nRet = LDoubleBufferObj.End(hDC);
if(nRet != SUCCESS)
return nRet;
if ((rcBall.bottom) > rcClient.bottom)
dy = -1;
if (rcBall.top < 0)
dy = 1;
if (rcBall.left < 0)
dx = 1;
if ((rcBall.right) > rcClient.right)
dx = -1;
OffsetRect(&rcBall, dx, dy);
}
// Cleanup
nRet = Bitmap.Free();
if(nRet != SUCCESS)
return nRet;
nRet = LDoubleBufferObj.DestroyHandle();
if(nRet != SUCCESS)
return nRet;
DeleteObject(hBrush);
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document