网摘-获取屏幕dc并且将其画面显示在窗体中

2021-05-23 12:29

阅读:453

  HWND hWnd = ::GetDesktopWindow();//获得屏幕的HWND.
 HDC hScreenDC = ::GetDC(hWnd);   //获得屏幕的HDC.
 HDC MemDC = ::CreateCompatibleDC(hScreenDC);
 RECT rect; 
 ::GetWindowRect(hWnd,&rect);
 SIZE screensize;
 screensize.cx=rect.right-rect.left;
 screensize.cy=rect.bottom-rect.top;
 hBitmap = ::CreateCompatibleBitmap(hScreenDC,screensize.cx,screensize.cy);
 HGDIOBJ hOldBMP = ::SelectObject(MemDC,hBitmap);
 ::BitBlt(MemDC,0,0,screensize.cx,screensize.cy,hScreenDC,rect.left,rect.top,SRCCOPY);//将屏幕画布拷贝到内存画布上
 ::SelectObject(MemDC,hOldBMP);
 ::DeleteObject(MemDC);
 ::ReleaseDC(hWnd,hScreenDC);
    CDC *pDC=GetDC();//获取窗体的cdc
 HDC dDlgDC=pDC->m_hDC;//获取窗体的hdc
 HDC MemDC1 = CreateCompatibleDC(dDlgDC);//创建画布
 HGDIOBJ hOldBMP1 = ::SelectObject(MemDC1,hBitmap);//选入画布
 ::StretchBlt(dDlgDC,0,0,600,400,MemDC1,0,0,screensize.cx,screensize.cy,SRCCOPY);//将内存画布缩略显示到窗体中
 ::SelectObject(MemDC1,hOldBMP1);//选出画布
 ::DeleteObject(MemDC1);//删除内存hdc
 ::ReleaseDC(m_hWnd,dDlgDC);//释放实际窗体的hdc

 

 

windows AP:

HDC GetDC( HWND hWnd // handle to window);

Parameters

hWnd

[in] Handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen.


评论


亲,登录后才可以留言!