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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
| Option Explicit
' Ìîäóëü modMain.bas
' © Êðèâîóñ Àíàòîëèé Àíàòîëüåâè÷ (The trick), 2014
' Ðåàëèçàöèÿ "ëèíçû"
' Óâåëè÷èòü - êîëåñèêî ââåðõ, óìåíüøèòü - âíèç
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type PAINTSTRUCT
hdc As Long
fErase As Long
rcPaint As RECT
fRestore As Long
fIncUpdate As Long
rgbReserved(32) As Byte
End Type
Private Type WINDOWPOS
hwnd As Long
hWndInsertAfter As Long
x As Long
y As Long
cx As Long
cy As Long
flags As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function BeginPaint Lib "user32" (ByVal hwnd As Long, lpPaint As PAINTSTRUCT) As Long
Private Declare Function EndPaint Lib "user32" (ByVal hwnd As Long, lpPaint As PAINTSTRUCT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function InvertRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function ScrollDC Lib "user32" (ByVal hdc As Long, ByVal dx As Long, ByVal dy As Long, lprcScroll As Any, lprcClip As Any, ByVal hrgnUpdate As Long, lprcUpdate As Any) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function RedrawWindow Lib "user32" (ByVal hwnd As Long, lprcUpdate As Any, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function SetDCPenColor Lib "gdi32" (ByVal hdc As Long, ByVal colorref As Long) As Long
Private Const DC_PEN = 19
Private Const RDW_INVALIDATE = &H1
Private Const RDW_UPDATENOW = &H100
Private Const WM_WINDOWPOSCHANGING = &H46
Private Const HWND_TOPMOST = -1
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const GWL_WNDPROC = &HFFFFFFFC
Private Const WM_PAINT = &HF
Private Const WM_MOUSEWHEEL = &H20A&
Private Const HTCAPTION = 2
Private Const WM_NCHITTEST = &H84
Dim lpPrevWndProc As Long
Dim bBmp As Long
Dim oBmp As Long
Dim tDc As Long
Dim oPos As WINDOWPOS
Dim w As Long, h As Long, bi As BITMAPINFO, pix() As Long, out() As Long, Strength As Single
Public Sub Hook()
Dim hRgn As Long
Strength = 0.2
w = frmTest.ScaleWidth: h = frmTest.ScaleHeight
bi.bmiHeader.biSize = Len(bi.bmiHeader)
bi.bmiHeader.biBitCount = 32
bi.bmiHeader.biPlanes = 1
bi.bmiHeader.biWidth = w
bi.bmiHeader.biHeight = h
ReDim pix(w * h - 1)
ReDim out(UBound(pix))
tDc = CreateCompatibleDC(frmTest.hdc)
bBmp = CreateCompatibleBitmap(frmTest.hdc, w, h)
oBmp = SelectObject(tDc, bBmp)
Prepare frmTest.Left / Screen.TwipsPerPixelX, frmTest.Top / Screen.TwipsPerPixelY
hRgn = CreateEllipticRgn(0, 0, w, h)
SetWindowRgn frmTest.hwnd, hRgn, False
SetWindowPos frmTest.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
lpPrevWndProc = SetWindowLong(frmTest.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Public Sub UnHook()
SetWindowLong frmTest.hwnd, GWL_WNDPROC, lpPrevWndProc
SelectObject tDc, oBmp
DeleteDC tDc
DeleteObject bBmp
End Sub
Private Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Debug.Print Msg
Select Case Msg
Case WM_WINDOWPOSCHANGING
Dim wp As WINDOWPOS
CopyMemory wp, ByVal lParam, Len(wp)
WndProc = OnPosChanging(hwnd, wp)
Case WM_NCHITTEST
WndProc = HTCAPTION
Case WM_PAINT
WndProc = OnPaint(hwnd)
Case WM_MOUSEWHEEL
WndProc = OnWheel(hwnd, (wParam \ &H10000))
Case Else
WndProc = CallWindowProc(lpPrevWndProc, hwnd, Msg, wParam, lParam)
End Select
End Function
Private Function OnWheel(ByVal hwnd As Long, ByVal Value As Integer) As Long
Value = Value \ 120
Strength = Strength + Value / 30
If Strength > 1 Then Strength = 1 Else If Strength < 0 Then Strength = 0
MakeLens
RedrawWindow hwnd, ByVal 0, 0, RDW_INVALIDATE
End Function
Private Function OnPosChanging(ByVal hwnd As Long, Pos As WINDOWPOS) As Long
Dim dx As Long, dy As Long
If Pos.flags And SWP_NOMOVE Then Exit Function
dx = Pos.x - oPos.x
dy = Pos.y - oPos.y
Prepare dx, dy
RedrawWindow hwnd, ByVal 0, 0, RDW_INVALIDATE Or RDW_UPDATENOW
oPos = Pos
End Function
Private Function OnPaint(ByVal hwnd As Long) As Long
Dim ps As PAINTSTRUCT, opn As Long
BeginPaint hwnd, ps
SetDIBitsToDevice ps.hdc, 0, 0, w, h, 0, 0, 0, h, out(0), bi, 0
opn = SelectObject(ps.hdc, GetStockObject(DC_PEN))
SetDCPenColor ps.hdc, &HE0E0E0
Ellipse ps.hdc, 1, 1, w - 2, h - 2
SelectObject ps.hdc, opn
EndPaint hwnd, ps
End Function
Private Sub MakeLens()
Dim x As Long, y As Long
Dim cx As Single, cy As Single
Dim nx As Long, ny As Long
Dim r As Single
Dim pt As Long
SelectObject tDc, oBmp
GetDIBits tDc, bBmp, 0, h, pix(0), bi, 0
SelectObject tDc, bBmp
For y = 0 To h - 1: For x = 0 To w - 1
cx = x / w - 0.5: cy = y / h - 0.5
r = Sqr(cx * cx + cy * cy)
nx = (cx + 0.5 + Strength * cx * ((r - 1) / 0.5)) * (w - 1)
ny = (cy + 0.5 + Strength * cy * ((r - 1) / 0.5)) * (h - 1)
out(pt) = pix(ny * w + nx)
pt = pt + 1
Next: Next
End Sub
Private Sub Prepare(ByVal dx As Long, ByVal dy As Long)
Dim dDC As Long, x As Long, y As Long
dDC = GetDC(0)
ScrollDC tDc, -dx, -dy, ByVal 0, ByVal 0, ByVal 0, ByVal 0
Select Case dx
Case Is > 0
x = oPos.x + w: y = oPos.y + dy
BitBlt tDc, w - dx, 0, dx, h, dDC, x, y, vbSrcCopy
Case Is < 0
x = oPos.x + dx: y = oPos.y + dy
BitBlt tDc, 0, 0, -dx, h, dDC, x, y, vbSrcCopy
End Select
Select Case dy
Case Is > 0
x = oPos.x + dx: y = oPos.y + h
BitBlt tDc, 0, h - dy, w, dy, dDC, x, y, vbSrcCopy
Case Is < 0
x = oPos.x + dx: y = oPos.y + dy
BitBlt tDc, 0, 0, w, -dy, dDC, x, y, vbSrcCopy
End Select
ReleaseDC 0, dDC
MakeLens
End Sub |