Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BOOL Monitor::GetScreenPixels(BYTE * CONST pixels) CONST {
- if (!pixels) {
- return FALSE;
- }
- INT screenWidth = GetWidth();
- INT screenHeight = GetHeight();
- HDC hdcMonitor = CreateDC(m_displayDeviceName.c_str(), NULL, NULL, NULL);
- BITMAPINFO bmi = { 0 };
- bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
- bmi.bmiHeader.biWidth = screenWidth;
- bmi.bmiHeader.biHeight = -screenHeight;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = GetDeviceCaps(hdcMonitor, BITSPIXEL);
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biXPelsPerMeter = GetDeviceCaps(hdcMonitor, HORZRES) * 1000 / GetDeviceCaps(hdcMonitor, HORZSIZE);
- bmi.bmiHeader.biYPelsPerMeter = GetDeviceCaps(hdcMonitor, VERTRES) * 1000 / GetDeviceCaps(hdcMonitor, VERTSIZE);
- //Create a device context and bitmap in memory
- HDC hdcMem = CreateCompatibleDC(hdcMonitor);
- HBITMAP hBmpMem = CreateCompatibleBitmap(hdcMonitor, screenWidth, screenHeight);
- SelectObject(hdcMem, hBmpMem);
- BitBlt(hdcMem, 0, 0, screenWidth, screenHeight, hdcMonitor, 0, 0, SRCCOPY); //This is the problem
- GetDIBits(hdcMem, hBmpMem, 0, screenHeight, pixels, &bmi, DIB_RGB_COLORS);
- //Free memory
- DeleteDC(hdcMem);
- DeleteDC(hdcMonitor);
- DeleteObject(hBmpMem);
- return TRUE;
- }
Add Comment
Please, Sign In to add comment