过程名:    CreateBMPFromWindow
功能:      获得一个句柄为Hwnd的窗口的图象
参数:      Hwnd: 窗体句柄
             PicBitNum: 图象位数(15,16,24,32)
返回值:    TBitmap
function CreateBMPFromWindow(Hwnd: THandle;PicBitNum: Byte): TBitmap;
  
{创建一个空的Bitmap}
  
function CreateDibBMP(Dc: HDC;width,height: Integer): HBITMAP;
  
type
    DibRec 
= record
      bi: BITMAPINFOHEADER;
      ct: 
array[0..255of DWORD;
    
end;
  
var
    Dib: DibRec;
    lpBits: pointer;
    temp: TBitmapInfo;
  
begin
      dib.bi.biSize :
= sizeof(BITMAPINFOHEADER);
      dib.bi.biWidth :
= width;
      dib.bi.biHeight :
= height;
      dib.bi.biBitCount :
= PicBitNum;
      dib.bi.biPlanes :
= 1;
      dib.bi.biCompression :
= 0;
      dib.bi.biSizeImage :
= 0;
      dib.bi.biClrUsed :
= 0

      
if PicBitNum = 15 then
        Dib.bi.biBitCount :
= 16
      
else if PicBitNum = 16 then
      
begin
        Dib.bi.biCompression :
= BI_BITFIELDS;
        dib.ct[
0] := $F800;
        dib.ct[
1] := $07E0;
        dib.ct[
2] := $001F;
      
end;
     Move(dib,temp,SizeOf(dib));
     result :
= CreateDIBSection(Dc,temp,DIB_RGB_COLORS,lpBits,0,0);
  
end;
var
  rc: TRect;
  x,y,cx,cy: integer;
  hdcScreen,hdcMemory: HDC;
begin
    GetWindowRect(hwnd, rc);
    x :
= rc.left;
    y :
= rc.top;
    cx :
= rc.right - rc.left;
    cy :
= rc.bottom - rc.top;
    hdcScreen :
= GetDC(0);
    hdcMemory :
= CreateCompatibleDC(0);
    result :
= TBitmap.Create;
    Result.Handle :
= CreateDibBMP(hdcScreen, cx, cy);
    SelectObject(hdcMemory, result.Handle);
    BitBlt(hdcMemory, 
00, cx, cy, hdcScreen, x, y, SRCCOPY);
    DeleteDC(hdcMemory);
    ReleaseDC(
0, hdcScreen);
end;

 


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2021-11-27
  • 2022-01-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
相关资源
相似解决方案