DB
Size: a a a
DB
VN
VN
M
M
К
DB
M
DB
M
DB
int Capture(int fLeft, int fTop, int fWidth, int fHeight, void *res) {
CURSORINFO cursor = { sizeof(cursor) };
GetCursorInfo(&cursor);
if (fLeft <= -0xffffff) {
fLeft = cursor.ptScreenPos.x - fWidth / 2;
}
if (fTop <= -0xffffff) {
fTop = cursor.ptScreenPos.y - fHeight / 2;
}
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, fWidth, fHeight);
if (!hDesktopWnd) logError(__LINE__);
if (!hDesktopDC) logError(__LINE__);
if (!hCaptureDC) logError(__LINE__);
if (!hCaptureBitmap) logError(__LINE__);
if (!SelectObject(hCaptureDC, hCaptureBitmap)) {
logError(__LINE__);
}
if (!BitBlt(hCaptureDC, 0, 0, fWidth, fHeight, hDesktopDC, fLeft, fTop, SRCCOPY | CAPTUREBLT)) {
logError(__LINE__);
}
BITMAPINFO bmi = {0};
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biWidth = fWidth;
bmi.bmiHeader.biHeight = -fHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
// RGBQUAD pPixels[fWidth * fHeight];
int linesCopied = -1;
linesCopied = GetDIBits(hCaptureDC, hCaptureBitmap, 0, fHeight, res, &bmi, DIB_RGB_COLORS);
if (!linesCopied) {
logError(__LINE__);
}
ReleaseDC(hDesktopWnd, hDesktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
return 0; // TODO: return error code here
}
DB
linesCopied = GetDIBits(hCaptureDC, hCaptureBitmap, 0, fHeight, res, &bmi, DIB_RGB_COLORS);
DB