VOID BitmapDemo (HWND hwnd)
{
HDC hDC, // Handle to the display device context
hDCMem; // Handle to the memory device context
HBITMAP hBitmap, // Handle to the new bitmap
hOldBitmap; // Handle to the old bitmap
static int iCoordinate[200][4];
int i, j,
iXSrc, iYSrc, // x and y coordinates of the source
// Rectangle's upper-left corner
iXDest, iYDest, // x and y coordinates of the destination
// Rectangle's upper-left corner
iWidth, iHeight; // Width and height of the bitmap
// Retrieve the handle to a display device context for the client
// area of the window (hwnd).
if (!(hDC = GetDC (hwnd)))
return;
SendMessage(hwnd,WM_ERASEBKGND,(WPARAM)hDC,NULL);
// Create a memory device context compatible with the device.
hDCMem = CreateCompatibleDC (hDC);
// Retrieve the width and height of windows display elements.
iWidth = 600;
iHeight = 600;
// Create a bitmap compatible with the device associated with the
// device context.
hBitmap = CreateCompatibleBitmap (hDC, iWidth, iHeight);
// Select the new bitmap object into the memory device context.
hOldBitmap = (HBITMAP)SelectObject (hDCMem, hBitmap);
for (i = 0; i < 2; i++)
{
for (j = 0; j < 200; j++)
{
if (i == 0)
{
iCoordinate[j][0] = iXDest = iWidth * (rand () % 10);
iCoordinate[j][1] = iYDest = iHeight * (rand () % 10);
iCoordinate[j][2] = iXSrc = iWidth * (rand () % 10);
iCoordinate[j][3] = iYSrc = iHeight * (rand () % 10);
}
else
{
iXDest = iCoordinate[200 - 1 - j][0];
iYDest = iCoordinate[200 - 1 - j][1];
iXSrc = iCoordinate[200 - 1 - j][2];
iYSrc = iCoordinate[200 - 1 - j][3];
}
// Transfer pixels from the source rectangle to the destination
// rectangle.
BitBlt (hDCMem, 0, 0, iWidth, iHeight, hDC, iXDest, iYDest,
SRCCOPY);
BitBlt (hDC, iXDest, iYDest, iWidth, iHeight, hDC, iXSrc, iYSrc,
SRCCOPY);
}
}
// Select the old bitmap back into the device context.
SelectObject (hDC, hOldBitmap);
SaveBitmapToFile(hBitmap,"teest.bmp",0);
// Delete the bitmap object and free all resources associated with it.
DeleteObject (hBitmap);
// Delete the memory device context and the display device context.
DeleteDC (hDCMem);
ReleaseDC (hwnd,hDC);
return;
}
I'm trying to take a screenshot every 300 secs,but they start getting black.Why? How can I solve this?
↧
If I take too many screenshots the pics get black
↧