-
Notifications
You must be signed in to change notification settings - Fork 3
/
frmAreaCapture.pas
143 lines (124 loc) · 2.77 KB
/
frmAreaCapture.pas
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
unit frmAreaCapture;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs;
type
TAreaCapturer = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormPaint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
fDragging: Boolean;
X1, Y1, X2, Y2: Integer;
procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND;
procedure UpdateRect;
public
{ Public declarations }
fRect: TRect;
fBmp: TBitmap;
end;
implementation
{$R *.lfm}
function Max(x, y: Integer): Integer;
begin
if x > y then
Result := x
else
Result := y;
end;
function Min(x, y: Integer): Integer;
begin
if x < y then
Result := x
else
Result := y;
end;
procedure Swap(var x, y: Integer);
var
z: Integer;
begin
z := x;
x := y;
y := z;
end;
procedure CheckRect(var R: TRect);
begin
if R.Right < R.Left then
Swap(R.Left, R.Right);
if R.Bottom < R.Top then
Swap(R.Bottom, R.Top);
end;
procedure TAreaCapturer.UpdateRect;
begin
SetRect(fRect, X1, Y1, X2, Y2);
CheckRect(fRect);
Canvas.DrawFocusrect(fRect);
end;
procedure TAreaCapturer.FormCreate(Sender: TObject);
var
aDC: HDC;
begin
fBMP := TBitmap.Create;
fBMP.Width := Screen.Width;
fBMP.Height := Screen.Height;
aDC := GetDC(0);
BitBlt(fBMP.Canvas.handle, 0, 0, Screen.Width, Screen.Height,
aDC, 0, 0, srcCopy);
ReleaseDC(0, aDC);
SetBounds(0, 0, Screen.Width, Screen.Height);
end;
procedure TAreaCapturer.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if mbLeft = Button then
begin
fDragging := True;
X1 := X;
Y1 := Y;
X2 := X;
Y2 := Y;
UpdateRect;
end;
end;
procedure TAreaCapturer.FormMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if fDragging then
begin
Canvas.DrawFocusrect(fRect);
X2 := X;
Y2 := Y;
UpdateRect;
end;
end;
procedure TAreaCapturer.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if fDragging then
begin
Canvas.DrawFocusrect(fRect);
fDragging := False;
end;
ModalResult := mrOk;
end;
procedure TAreaCapturer.FormPaint(Sender: TObject);
begin
Canvas.Draw(0, 0, fBMP);
end;
procedure TAreaCapturer.FormDestroy(Sender: TObject);
begin
fBMP.Free;
end;
procedure TAreaCapturer.WMEraseBkGnd(var Msg: TWMEraseBkGnd);
begin
Msg.Result := 1;
end;
end.