-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mirror.pas
186 lines (146 loc) · 3.65 KB
/
Mirror.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
unit Mirror;
interface
uses
forms, windows, sysutils, graphics, System.Classes, Unit1;
type
// THalfToneOption =(AutoHalftone, UseHalftone, NoHalftone);
TMirrorDrawer = class(TThread)
private
bmp: Tbitmap;
Icon: TIcon;
procedure ScreenShot2(var destBitmap: Tbitmap);
procedure DrawCursor(ScreenShotBitmap: Tbitmap);
protected
procedure Execute; override;
public
IncludeMouse: Boolean;
Monitor: TMonitor;
MirrorMonitor: TMonitor;
UseHalfTone: Boolean;
VerticalInvert: Boolean;
// HalfToneMode: THalfToneOption;
constructor Create(mon: TMonitor; monmirr: TMonitor);
destructor Destroy; override;
end;
implementation
constructor TMirrorDrawer.Create(mon: TMonitor; monmirr: TMonitor);
begin
Monitor := mon;
if (monmirr = nil) then
MirrorMonitor := mon
else
MirrorMonitor := monmirr;
self.FreeOnTerminate := true;
inherited Create(true);
UseHalfTone := false;
bmp := Tbitmap.Create;
bmp.PixelFormat := TPixelformat.pf16bit;
bmp.SetSize(MirrorMonitor.width, MirrorMonitor.height);
end;
procedure TMirrorDrawer.ScreenShot2(var destBitmap: Tbitmap);
var
wOrig, hOrig: integer;
DC: HDC;
hWin: Cardinal;
r: TRect;
w, h: integer;
pt: Tpoint;
begin
w := destBitmap.width;
h := destBitmap.height;
hWin := GetDesktopWindow;
DC := GetDC(hWin);
// wOrig := GetDeviceCaps (DC, HORZRES) ;
// hOrig := GetDeviceCaps (DC, VERTRES) ;
wOrig := Monitor.width;
hOrig := Monitor.height;
if (UseHalfTone) then
begin
GetBrushOrgEx(destBitmap.Canvas.Handle, pt);
SetStretchBltMode(destBitmap.Canvas.Handle, HALFTONE);
SetBrushOrgEx(destBitmap.Canvas.Handle, pt.x, pt.y, @pt);
end;
try
if(VerticalInvert) then
StretchBlt(destBitmap.Canvas.Handle,
0 ,
h,
w,
-h ,
DC,
Monitor.Left,
Monitor.Top,
wOrig ,
hOrig ,
SRCCOPY)
else
StretchBlt(destBitmap.Canvas.Handle,
w ,
0,
-w,
h ,
DC,
Monitor.Left,
Monitor.Top,
wOrig ,
hOrig ,
SRCCOPY) ;
finally
ReleaseDC(hWin, DC);
end;
end;
procedure TMirrorDrawer.DrawCursor(ScreenShotBitmap: Tbitmap);
var
r: TRect;
CI: TCursorInfo;
II: TIconInfo;
begin
r := ScreenShotBitmap.Canvas.ClipRect;
Icon := TIcon.Create;
try
CI.cbSize := SizeOf(CI);
if GetCursorInfo(CI) then
if CI.Flags = CURSOR_SHOWING then
begin
Icon.Handle := CopyIcon(CI.hCursor);
if GetIconInfo(Icon.Handle, II) then
begin
ScreenShotBitmap.Canvas.Draw(ci.ptScreenPos.x - Integer(II.xHotspot) -
r.Left, ci.ptScreenPos.y - Integer(II.yHotspot) - r.Top, Icon);
end;
end;
finally
Icon.Free;
end;
end;
procedure TMirrorDrawer.Execute;
begin
NameThreadForDebugging('TMirrorDrawer');
if (UseHalfTone) then
UseHalfTone := ((Monitor.width <> MirrorMonitor.width) or
(Monitor.height <> MirrorMonitor.height));
while not self.Terminated do
begin
// bmp.Canvas.Lock;
// bmp.Canvas.Unlock;
Synchronize(
procedure
begin
ScreenShot2(bmp);
if (IncludeMouse) then
DrawCursor(bmp);
Form1.Image1.Picture.Assign(bmp);
// Form1.Image1.Invalidate;
// Form1.Image1.Picture.BitMap.Assign(bmp );
end);
sleep(4);
end;
{ Place thread code here }
end;
destructor TMirrorDrawer.Destroy;
begin
if (assigned(bmp)) then
bmp.Free;
inherited Destroy;
end;
end.