|
|
@ -307,6 +307,43 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
// Get the client area for size calculation
|
|
|
|
RECT rcClient; |
|
|
|
GetClientRect(hWnd, &rcClient); |
|
|
|
|
|
|
|
//This is the best stretch mode
|
|
|
|
SetStretchBltMode(hdcWindow,HALFTONE); |
|
|
|
|
|
|
|
//The source DC is the entire screen and the destination DC is the current window (HWND)
|
|
|
|
if(!StretchBlt(hdcWindow, |
|
|
|
0,0, |
|
|
|
rcClient.right, rcClient.bottom, |
|
|
|
hdcScreen, |
|
|
|
0,0, |
|
|
|
GetSystemMetrics (SM_CXSCREEN), |
|
|
|
GetSystemMetrics (SM_CYSCREEN), |
|
|
|
SRCCOPY)) |
|
|
|
{ |
|
|
|
MessageBox(hWnd, L"StretchBlt has failed",L"Failed", MB_OK); |
|
|
|
DeleteObject(hdcMemDC); |
|
|
|
ReleaseDC(NULL,hdcScreen); |
|
|
|
ReleaseDC(hWnd,hdcWindow); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
// Create a compatible bitmap from the Window DC
|
|
|
|
hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top); |
|
|
|
|
|
|
|
if(!hbmScreen) |
|
|
|
{ |
|
|
|
MessageBox(hWnd, L"CreateCompatibleBitmap Failed",L"Failed", MB_OK); |
|
|
|
DeleteObject(hbmScreen); |
|
|
|
DeleteObject(hdcMemDC); |
|
|
|
ReleaseDC(NULL,hdcScreen); |
|
|
|
ReleaseDC(hWnd,hdcWindow); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
int width = GetDeviceCaps(hdcScreen, HORZRES); |
|
|
|
int height = GetDeviceCaps(hdcScreen, VERTRES); |
|
|
|
|
|
|
@ -316,7 +353,7 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { |
|
|
|
// Bit block transfer into our compatible memory DC.
|
|
|
|
if(!BitBlt(hdcMemDC, |
|
|
|
0,0, |
|
|
|
width, height, |
|
|
|
rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, |
|
|
|
hdcWindow, |
|
|
|
0,0, |
|
|
|
SRCCOPY)) |
|
|
@ -394,43 +431,6 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { |
|
|
|
//Close the handle for the file that was created
|
|
|
|
CloseHandle(hFile); |
|
|
|
|
|
|
|
// Get the client area for size calculation
|
|
|
|
RECT rcClient; |
|
|
|
GetClientRect(hWnd, &rcClient); |
|
|
|
|
|
|
|
//This is the best stretch mode
|
|
|
|
SetStretchBltMode(hdcWindow,HALFTONE); |
|
|
|
|
|
|
|
//The source DC is the entire screen and the destination DC is the current window (HWND)
|
|
|
|
if(!StretchBlt(hdcWindow, |
|
|
|
0,0, |
|
|
|
rcClient.right, rcClient.bottom, |
|
|
|
hdcScreen, |
|
|
|
0,0, |
|
|
|
GetSystemMetrics (SM_CXSCREEN), |
|
|
|
GetSystemMetrics (SM_CYSCREEN), |
|
|
|
SRCCOPY)) |
|
|
|
{ |
|
|
|
MessageBox(hWnd, L"StretchBlt has failed",L"Failed", MB_OK); |
|
|
|
DeleteObject(hdcMemDC); |
|
|
|
ReleaseDC(NULL,hdcScreen); |
|
|
|
ReleaseDC(hWnd,hdcWindow); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
// Create a compatible bitmap from the Window DC
|
|
|
|
hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top); |
|
|
|
|
|
|
|
if(!hbmScreen) |
|
|
|
{ |
|
|
|
MessageBox(hWnd, L"CreateCompatibleBitmap Failed",L"Failed", MB_OK); |
|
|
|
DeleteObject(hbmScreen); |
|
|
|
DeleteObject(hdcMemDC); |
|
|
|
ReleaseDC(NULL,hdcScreen); |
|
|
|
ReleaseDC(hWnd,hdcWindow); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|