1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
RECT rc;
GetClientRect(GetDesktopWindow(), &rc);
HDC hDC = GetDC(0);
HBITMAP hBmp = CreateCompatibleBitmap(hDC, rc.right, rc.bottom);
SelectObject(hDC, hBmp);
//Draws screenshot to the hBmp
BitBlt(hDC, 0, 0, rc.right, rc.bottom, GetDC(NULL), 0, 0, SRCCOPY);
BYTE* buf = new BYTE[256*256*256];
BITMAPINFO bmi;
int a = GetDIBits(hDC, hBmp, 0, rc.bottom, NULL, &bmi, DIB_RGB_COLORS);
if(a == 0)
MessageBox(hWnd, "Error when filling BMI", NULL, NULL);
int b = GetDIBits(hDC, hBmp, 0, rc.bottom, buf, &bmi, DIB_RGB_COLORS);
if(b == 0)
MessageBox(hWnd, "Error when filling buffer", NULL, NULL);
//hBmp == screenshot
ReleaseDC(hWnd, hDC);
DeleteDC(hDC);
DeleteObject(hBmp);
|