Code:
void Screenshot(HDC hDC, HWND hwnd)
{
SIZE size;
RECT rect;
GetClientRect(hwnd, &rect);
size.cx = GetSystemMetrics(SM_CXSCREEN);
size.cy = GetSystemMetrics(SM_CYSCREEN);
HDC hdcMemory = GetDC(GetDesktopWindow());
HBITMAP hBitmap = CreateCompatibleBitmap(hdcMemory, size.cx, size.cy);
if(hBitmap) {
BitBlt(hDC, 0, 0, size.cx, size.cy, hdcMemory, 0, 0, SRCCOPY);
//Save(hwnd, CreateInfoHeader(hwnd, hBitmap), hBitmap, hDC);
DeleteDC(hdcMemory);
DeleteObject(hBitmap);
}
ReleaseDC(NULL, hDC);
}
You're saving an empty bitmap! You copy the screen image to your window but not the memory bitmap. Here is an edited, commented but untested version of your function:
Code:
void Screenshot(HDC hDC, HWND hwnd)
{
RECT rect;
GetClientRect(hwnd, &rect); /* Not currently used */
/* Get the size of the screen */
SIZE size;
size.cx = GetSystemMetrics(SM_CXSCREEN);
size.cy = GetSystemMetrics(SM_CYSCREEN);
/* Get a device context for the screen */
HDC hdcScreen = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
/* Create a memory bitmap and put it in a memory DC so we can draw on it */
HDC hdcShot = CreateCompatibleDC(hdcScreen);
HBITMAP hBitmapShot = CreateCompatibleBitmap(hdcScreen, size.cx, size.cy);
HBITMAP hBitmapOld = (HBITMAP) SelectObject(hdcShot, hBitmapShot);
/* Copy the screen image to our memory bitmap */
BitBlt(hdcShot, 0, 0, size.cx, size.cy, hdcScreen, 0, 0, SRCCOPY);
/* You can copy the screen to your window (hDC) here if needed */
/* BitBlt(hDC, 0, 0, size.cx, size.cy, hdcScreen, 0, 0, SRCCOPY); */
/* Save our memory bitmap to file */
Save(hwnd, CreateInfoHeader(hwnd, hBitmapShot), hBitmapShot, hdcShot);
/* Cleanup memory bitmap and DC */
SelectObject(hdcShot, hBitmapOld);
DeleteObject(hBitmapShot);
DeleteDC(hdcShot);
/* Cleanup screen DC */
DeleteDC(hdcScreen);
}