19,468
社区成员
发帖
与我相关
我的任务
分享
HBITMAP GetWindowBitmap(HWND hWnd)
{
typedef BOOL ( __stdcall *pPrintWindow )(HWND hWnd,HDC hdcBlt,UINT nFlags);
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;
}