在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
功能: 获得一个句柄为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..255] of 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, 0, 0, cx, cy, hdcScreen, x, y, SRCCOPY); DeleteDC(hdcMemory); ReleaseDC(0, hdcScreen); end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论