16,473
社区成员
发帖
与我相关
我的任务
分享
//-------------------------------------------------------------
// Function : GetWindowBitmap
// Description : Copy a block bitmap from the window
// or screen Specifies location
// Paratmeters :
//-------------------------------------------------------------
HBITMAP GetWindowBitmap(HWND hwnd, LPRECT lpRect)
{
if( !lpRect )
return NULL;
HDC hDC;
HDC hMemDC;
HBITMAP hBitmap = NULL;
HBITMAP hOldBitmap;
// Get window or screen DC
if( hwnd == NULL )
hDC = GetDC(HWND_DESKTOP);
else
hDC = GetWindowDC(hwnd);
if( hDC == NULL )
return NULL;
hMemDC = CreateCompatibleDC(hDC);
hBitmap = CreateCompatibleBitmap(hDC, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top);
if( hBitmap == NULL)
return NULL;
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, hDC, lpRect->left, lpRect->top, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);
ReleaseDC(hwnd, hDC);
return hBitmap;
}