var
Form1: TForm1;
xpos, ypos, xposEnd, yposEnd: integer;
draw : boolean = false;
DCanvas: TCanvas;
DHandle: HWND;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
draw := true;
Xpos := X;
Ypos := y;
DHandle := GetDC(0);
DCanvas := TCanvas.Create;
try
DCanvas.Handle := DHandle;
DCanvas.Brush.Style:=bsClear;
DCanvas.Pen.Color := clRed;
DCanvas.Pen.Mode := pmNotXor;
DCanvas.Pen.Width := 3;
except
ReleaseDC(0, DHandle);
end;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if draw
and (DHandle <> 0)
then
try
// hier vorher ein FillRect, Refresh oder Repaint eingesetzt, was nicht funktioniert
DCanvas.Rectangle(Xpos, Ypos, x, y);
except
ReleaseDC(0, DHandle);
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
bitmap: TBitmap;
OldBkMode: integer;
begin
xposend := x;
yposEnd := y;
draw := False;
if DHandle <> 0
then
try
Bitmap := TBitmap.Create;
Bitmap.Width := Screen.Width;
Bitmap.Height := Screen.Height;
BitBlt(Bitmap.Canvas.Handle, 0, 0, xposend - xpos, yposend - ypos, DHandle, xpos, ypos, SRCCOPY);
OldBkMode := SetBkMode(Bitmap.Canvas.Handle, Ord(TRANSPARENT));
Bitmap.Canvas.Font.Color := clred;
Bitmap.Canvas.TextOut(10, 10, '
Captured By MJ');
SetBkMode(Bitmap.Canvas.Handle, OldBkMode);
Image1.Picture.Bitmap := bitmap;
finally
ReleaseDC(0, DHandle);
DCanvas.Free;
ManageVisibility(
Handle);
Image1.Visible := True;
end;
end;