1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| ...
private
{ private declarations }
Rect4Selection :TRect;
FStartPoint, FEndPoint: TPoint;
procedure WMEraseBkGnd( var message: TLMERASEBKGND );
function GetDragRect: TRect;
public
{ public declarations }
Bmp4Selection: TBitmap;
ZoneCopieFaite: boolean;
FullCopieFaite: boolean;
FormCopieFaite: boolean;
Echapp: boolean;
property DragRect: TRect read GetDragRect;
end;
procedure Tfrm4CopieEcran.DrawDragRect;
begin
DrawFocusRect(Canvas.Handle, DragRect);
end;
function Tfrm4CopieEcran.GetDragRect: TRect;
begin
Result.Left := Min( FStartpoint.X, FEndPoint.X );
Result.Top := Min( FStartpoint.Y, FEndPoint.Y );
Result.Right := Max( FStartpoint.X, FEndPoint.X );
Result.Bottom := Max( FStartpoint.Y, FEndPoint.Y );
end;
// copie d'une région sélectionnée à la souris
procedure Tfrm4CopieEcran.imgMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then begin
FStartPoint:= Point( X, Y );
FEndPoint := FStartPoint;
MouzeDown := true;
DrawDragRect;
end; { if }
end;
procedure Tfrm4CopieEcran.imgMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if MouzeDown then begin
DrawDragRect;
FEndPoint:= Point( X, Y );
DrawDragRect;
end; { if }
end;
procedure Tfrm4CopieEcran.imgMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
tmp: integer;
begin
if MouzeDown then begin
DrawDragRect;
FEndPoint:= Point( X, Y );
MouzeDown := False;
with Rect4Selection do begin
Left:= FStartPoint.X; Top:= FStartPoint.Y;
Right:= FEndPoint.X; Bottom:= FEndPoint.Y;
// en cas de sélection à l'envers :
if Left > Right then begin tmp := Left; Left := Right; Right := tmp; end;
if Top > Bottom then begin tmp := Top; Top := Bottom; Bottom := tmp; end;
end;
with Bmp4Selection do begin
PixelFormat := pf24bit;
with Rect4Selection do begin
Width := Right-Left; Height := Bottom-Top;
end;
Application.ProcessMessages;
Canvas.CopyRect(Rect(0,0,Width,Height), img.Canvas, Rect4Selection);
//showmessage(format('%4d %4d %4d %4d', [0,0,Width,Height]));
//SaveToFile('/chemin/testrect.bmp'); // OK !
ZoneCopieFaite := True; // traitée dans le timer de la fiche appelante, pour lui rendre la main.
end;
end; { if }
Hide;
end; |
Partager