var
Form1: TForm1;
function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall;
external 'user32.dll' name 'PrintWindow';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
bmp: TBitmap;
wnd: cardinal;
rec: TRect;
begin
wnd := FindWindow(nil, '计算器'); // 查找窗口句柄,这里用计算器演示
GetWindowRect(wnd, rec); // 获取到计算器窗口的举行
bmp := TBitmap.Create;
try
bmp.Width := rec.Right - rec.Left;
bmp.Height := rec.Bottom - rec.Top;
bmp.PixelFormat := pf24bit;
PrintWindow(wnd, bmp.Canvas.Handle, 0);
bmp.SaveToFile('e:\计算器.bmp');
finally
bmp.Free;
end;
end;