LDoubleBuffer::End
#include "ltwrappr.h"
virtual L_INT LDoubleBuffer::End(hDC)
HDC hDC; |
/* handle to the target device context */ |
Displays the double buffered paint operations.
Parameter |
Description |
hDC |
Handle to the original target device context |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
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.
Required DLLs and Libraries
LTDIS For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
See Also
Functions: |
|
Topics: |
|
|
Example
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 --
* once with bDoubleBuffer set to FALSE
* once with bDoubleBuffer set to TRUE
to see the difference
hWnd -- window to paint image and bounce ball
pszFile -- file name of image to load
bDoubleBuffer - flag saying whether or not to double buffer the paints#define BALL_RADIUS 30
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; }