HBITMAP GetWindowBitmap(HWND hWnd)
{
typedef BOOL ( __stdcall *pPrintWindow )(HWND ,HDC ,UINT );
RECT rect;
HMODULE h;
h = LoadLibrary( "user32.dll" );
pPrintWindow p;
if( h )
{
p = ( pPrintWindow )::GetProcAddress( h, "PrintWindow" );
}
::GetWindowRect(hWnd,&rect);
HDC hScrDC=::GetDC(hWnd); //创建屏幕DC
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
HBITMAP bitmap=::CreateCompatibleBitmap(hScrDC,rect.right-rect.left,rect.bottom-rect.top); //创建兼容位图
HBITMAP OldBitmap=(HBITMAP)::SelectObject(hMemDC,bitmap); //把位图选进内存DC
p(hWnd,hMemDC,0);
HDC d;
HWND hw;
hw = ::GetDesktopWindow();
d = ::GetWindowDC( hw );
::BitBlt( d, 0, 0, 200, 200, hMemDC, 0, 0, SRCCOPY );
::SelectObject(hMemDC,OldBitmap);
::DeleteDC(hMemDC) ; //删除内存DC
::ReleaseDC(NULL,hScrDC) ; //释放屏幕DC
return bitmap;
}
后台截屏
最新推荐文章于 2024-05-16 03:03:53 发布