后台截屏
来源:互联网 发布:tunaproxy软件 编辑:程序博客网 时间:2024/06/01 08:49
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; }