Guest User

Untitled

a guest
Nov 17th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. BOOL Monitor::GetScreenPixels(BYTE * CONST pixels) CONST {
  2. if (!pixels) {
  3. return FALSE;
  4. }
  5.  
  6. INT screenWidth = GetWidth();
  7. INT screenHeight = GetHeight();
  8.  
  9. HDC hdcMonitor = CreateDC(m_displayDeviceName.c_str(), NULL, NULL, NULL);
  10.  
  11. BITMAPINFO bmi = { 0 };
  12. bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
  13. bmi.bmiHeader.biWidth = screenWidth;
  14. bmi.bmiHeader.biHeight = -screenHeight;
  15. bmi.bmiHeader.biPlanes = 1;
  16. bmi.bmiHeader.biBitCount = GetDeviceCaps(hdcMonitor, BITSPIXEL);
  17. bmi.bmiHeader.biCompression = BI_RGB;
  18. bmi.bmiHeader.biXPelsPerMeter = GetDeviceCaps(hdcMonitor, HORZRES) * 1000 / GetDeviceCaps(hdcMonitor, HORZSIZE);
  19. bmi.bmiHeader.biYPelsPerMeter = GetDeviceCaps(hdcMonitor, VERTRES) * 1000 / GetDeviceCaps(hdcMonitor, VERTSIZE);
  20.  
  21. //Create a device context and bitmap in memory
  22. HDC hdcMem = CreateCompatibleDC(hdcMonitor);
  23. HBITMAP hBmpMem = CreateCompatibleBitmap(hdcMonitor, screenWidth, screenHeight);
  24. SelectObject(hdcMem, hBmpMem);
  25.  
  26. BitBlt(hdcMem, 0, 0, screenWidth, screenHeight, hdcMonitor, 0, 0, SRCCOPY); //This is the problem
  27.  
  28. GetDIBits(hdcMem, hBmpMem, 0, screenHeight, pixels, &bmi, DIB_RGB_COLORS);
  29.  
  30. //Free memory
  31. DeleteDC(hdcMem);
  32. DeleteDC(hdcMonitor);
  33. DeleteObject(hBmpMem);
  34. return TRUE;
  35. }
Add Comment
Please, Sign In to add comment