procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
w=320;//矩形宽
h=240;//矩形高
var
bmp:tbitmap;
dc:hdc;
p:tpoint;
begin
try
bmp:=Tbitmap.Create;
with bmp do begin
PixelFormat:=pf32bit;
Width:=w;
Height:=h;
dc:=getdc(getdesktopwindow);
SetStretchBltMode(Canvas.Handle, HalfTone);
p:=clienttoscreen(point(x,y));
stretchBlt(Canvas.Handle,0,0,w,h,DC,p.x-(w shr 1),p.y-(h shr 1),w,h,SRCCOPY);
releasedc(h,dc);
SaveToFile('d:/test.bmp');
end;
finally
bmp.Free;
end;
end;