procedure GetScreen(var bmp: TBitmap);
var
dc : integer;
c : TCanvas;
R : TRect;
begin
bmp := TBitmap.Create;
dc := GetWindowDC(0);
try
c := TCanvas.Create;
c.Handle := dc;
R := Rect(0, 0, Screen.Width, Screen.Height);
bmp.Width := R.Right;
bmp.Height := R.Bottom;
bmp.Canvas.CopyRect(R, c, R);
c.Handle := 0;
c.Free;
finally
ReleaseDC(0, dc);
end;
end;
这是最简单的抓全屏的例子, 如果想抓获一个活动窗体, 可以先用GetForegroundWindow
函数得到当前活动窗口的句柄, 得到它的DC, 边界, 然后在CopyRect.