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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
int iLenX = 0;
int iLenY = 0;
// Checks whether to scan / poll the taskbar
if (SingleMonitorInfo::intCheckTaskbar)
{
iLenX = (SingleMonitorInfo::rcMonitorArea.right - SingleMonitorInfo::rcMonitorArea.left);
iLenY = (SingleMonitorInfo::rcMonitorArea.bottom - SingleMonitorInfo::rcMonitorArea.top);
}
else
{
iLenX = (SingleMonitorInfo::rcWorkArea.right - SingleMonitorInfo::rcWorkArea.left);
iLenY = (SingleMonitorInfo::rcWorkArea.bottom - SingleMonitorInfo::rcWorkArea.top);
}
unsigned long byteStreamSize = (iLenX * 4 * iLenY);
if (iLenX <= 0 && iLenY <= 0)
{
// ERROR HANDELING
/* "Error calculating desktop area" */
return 1;
}
HDC hDisplay = CreateDC(SingleMonitorInfo::szDeviceName, SingleMonitorInfo::szDeviceName, NULL, NULL);
if (!hDisplay)
{
// ERROR HANDELING
/* "Error creating DC" */
return 2;
}
HDC hBuffer = CreateCompatibleDC(hDisplay);
if (!hBuffer)
{
// ERROR HANDELING
/* "Error creating compatible DC" */
DeleteDC(hDisplay);
return 3;
}
HBITMAP hBitmap = CreateCompatibleBitmap(hDisplay, iLenX, iLenY);
if (!hBitmap)
{
// ERROR HANDELING
/* "Error creating compatible bitmap" */
DeleteDC(hBuffer);
DeleteDC(hDisplay);
return 4;
}
HBITMAP hPreviousBitmap = static_cast<HBITMAP>(SelectObject(hBuffer, hBitmap));
if (!hPreviousBitmap)
{
// ERROR HANDELING
/* "Error selecting previous bitmap" */
DeleteDC(hBuffer);
DeleteDC(hDisplay);
DeleteObject(hBitmap);
return 5;
}
if (!BitBlt(hBuffer, 0, 0, iLenX, iLenY, hDisplay, 0, 0, SRCCOPY))
{
// ERROR HANDELING
/* "Error with bit block transfer" */
SelectObject(hBuffer, hPreviousBitmap);
DeleteDC(hBuffer);
DeleteDC(hDisplay);
DeleteObject(hBitmap);
DeleteObject(hPreviousBitmap);
return 6;
}
BITMAP bmpDisplay;
if (!GetObject(hBitmap, sizeof(BITMAP), &bmpDisplay))
{
// ERROR HANDELING
/* "Cannot get bitmap object" */
SelectObject(hBuffer, hPreviousBitmap);
DeleteDC(hBuffer);
DeleteDC(hDisplay);
DeleteObject(hBitmap);
DeleteObject(hPreviousBitmap);
return 7;
}
BITMAPINFOHEADER bmpInfo;
bmpInfo.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.biWidth = bmpDisplay.bmWidth;
bmpInfo.biHeight = bmpDisplay.bmHeight;
bmpInfo.biPlanes = 1;
bmpInfo.biBitCount = 32;
bmpInfo.biCompression = BI_RGB;
bmpInfo.biSizeImage = 0;
bmpInfo.biXPelsPerMeter = 0;
bmpInfo.biYPelsPerMeter = 0;
bmpInfo.biClrUsed = 0;
bmpInfo.biClrImportant = 0;
unsigned char* lpBitmap = NULL;
lpBitmap = (unsigned char*)malloc(byteStreamSize);
if (!GetDIBits(hBuffer, hBitmap, 0, iLenY, lpBitmap, (BITMAPINFO *)&bmpInfo, DIB_RGB_COLORS))
{
// ERROR HANDELING
/* "GetDIBits failed" */
SelectObject(hBuffer, hPreviousBitmap);
DeleteDC(hBuffer);
DeleteDC(hDisplay);
DeleteObject(hBitmap);
DeleteObject(hPreviousBitmap);
free(lpBitmap);
return 8;
}
if (lpBitmap == NULL)
{
// ERROR HANDELING
/* "GetDIBits copy to lpBitmap failed" */
SelectObject(hBuffer, hPreviousBitmap);
DeleteDC(hBuffer);
DeleteDC(hDisplay);
DeleteObject(hBitmap);
DeleteObject(hPreviousBitmap);
free(lpBitmap);
return 9;
}
|