1,183
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.Button3Click(Sender: TObject);
var
hWind: HWND;
bitMap: TBitmap;
fileName: string;
begin
hWind := 0;
try
hWind := GetWinHandle();
if hWind = 0 then
begin
ShowMessage('客户端未启动');
Exit;
end;
Image1.Picture := nil;
bitMap := TBitmap.Create;
CaptureBitmap(hWind, 0, 0, 200, 200, bitMap);
Image1.Canvas.Draw(0, 0, bitMap);
fileName := FormatDateTime('HHMMss', Now) + 'b.bmp';
bitMap.SaveToFile(fileName);
finally
bitMap.Free;
end;
end;
procedure TForm1.CaptureBitmap(hWnd: HWND; x, y, width, height: Integer; var bitmap: TBitmap);
var
hWndDC: HDC;
hWndBitMap: HBITMAP;
MemDC: HDC;
begin
hWndDC := GetDC(hWnd);
MemDC := CreateCompatibleDC(hWndDC);
hWndBitMap := CreateCompatibleBitmap(hWndDC, width, height);
try
SelectObject(MemDC, hWndBitMap);
bitmap.Handle := hWndBitMap;
BitBlt(MemDC, 0, 0, width, height, hWndDC, x, y, SRCCOPY);
//bitmap.SaveToFile(FormatDateTime('HHMMss', Now) + 'a.bmp');
finally
DeleteObject(hWndBitMap);
DeleteDC(MemDC);
ReleaseDC(hWnd, hWndDC);
end;
end;