-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfrmBorderWindow.frm
503 lines (463 loc) · 18.7 KB
/
frmBorderWindow.frm
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
VERSION 5.00
Begin VB.Form frmBorderWindow
BorderStyle = 0 'None
Caption = "Dark¡áBorder"
ClientHeight = 450
ClientLeft = 0
ClientTop = 0
ClientWidth = 1305
Icon = "frmBorderWindow.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 450
ScaleWidth = 1305
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Begin VB.Timer tmrCheckFocus
Interval = 10
Left = -120
Top = 120
End
End
Attribute VB_Name = "frmBorderWindow"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'Dark¡áBorderWindow by IceLolly
'Date: 2018.8.8
'Please note that this window is used by Dark¡áWindowBorder and is NOT suggested to use directly.
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function I_want_to_fuck_Visual_Basic_since_it_does_not_let_me_to_use_SetFocus_as_a_function_name Lib _
"user32" Alias "SetFocus" (ByVal hWnd As Long) As Long
Enum BindPosition
TopPos = 0
LeftPos = 1
RightPos = 2
BottomPos = 3
End Enum
Private Const FACTOR = 5 * 15
Public BoundWindow As Long
Public UseSetParent As Boolean
Public CanSize As Boolean
Public Thickness As Integer
Public fColor As Long
Public nfColor As Long
Public MinW As Long
Public MinH As Long
Dim Pos As BindPosition
Dim Trans As Byte
Dim SizeMode As Integer
'0 1 2
' ¨I¡ü¨J
'3¡û ¡ú4
' ¨L¡ý¨K
'5 6 7
Dim bMoving As Boolean
Dim PrevRect As RECT
Dim NewX As Long, NewY As Long, _
NewW As Long, NewH As Long
Public Property Get BindPos() As BindPosition
BindPos = Pos
End Property
Public Property Let BindPos(DesirePos As BindPosition)
Pos = DesirePos
Select Case DesirePos
Case TopPos
Me.MousePointer = 7
Case BottomPos
Me.MousePointer = 7
Case LeftPos
Me.MousePointer = 9
Case RightPos
Me.MousePointer = 9
End Select
End Property
Public Property Get Transparency() As Byte
Transparency = Trans
End Property
Public Property Let Transparency(NewValue As Byte)
Trans = NewValue
SetWindowLongA Me.hWnd, GWL_EXSTYLE, GetWindowLongA(Me.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes Me.hWnd, 0, NewValue, LWA_ALPHA
End Property
Private Sub Form_GotFocus()
I_want_to_fuck_Visual_Basic_since_it_does_not_let_me_to_use_SetFocus_as_a_function_name BoundWindow
End Sub
Private Sub Form_Load()
SetWindowLongA Me.hWnd, GWL_STYLE, GetWindowLongA(Me.hWnd, GWL_STYLE) Or WS_CHILD
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If CanSize Then
If Button = 1 Then
Dim ParentHwnd As Long
Dim ParentRect As RECT
ParentHwnd = GetPropA(BoundWindow, "Parent")
GetWindowRect BoundWindow, PrevRect
If ParentHwnd <> 0 Then
GetWindowRect ParentHwnd, ParentRect
PrevRect.Left = PrevRect.Left - ParentRect.Left
PrevRect.Top = PrevRect.Top - ParentRect.Top
ClipCursor ParentRect
End If
bMoving = True
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMoving = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMoving Then
Exit Sub
End If
If Not CanSize Then
Me.MousePointer = 0
Exit Sub
End If
If Pos = TopPos Then
If X < Thickness * FACTOR Then
Me.MousePointer = 8
SizeMode = 0
ElseIf X > Me.Width - Thickness * FACTOR Then
Me.MousePointer = 6
SizeMode = 2
Else
Me.MousePointer = 7
SizeMode = 1
End If
ElseIf Pos = BottomPos Then
If X < Thickness * FACTOR Then
Me.MousePointer = 6
SizeMode = 5
ElseIf X > Me.Width - Thickness * FACTOR Then
Me.MousePointer = 8
SizeMode = 7
Else
Me.MousePointer = 7
SizeMode = 6
End If
ElseIf Pos = LeftPos Then
If Y < Thickness * (FACTOR - 1) Then
Me.MousePointer = 8
SizeMode = 0
ElseIf Y > Me.Height - Thickness * (FACTOR - 1) Then
Me.MousePointer = 6
SizeMode = 5
Else
Me.MousePointer = 9
SizeMode = 3
End If
ElseIf Pos = RightPos Then
If Y < Thickness * (FACTOR - 1) Then
Me.MousePointer = 6
SizeMode = 2
ElseIf Y > Me.Height - Thickness * (FACTOR - 1) Then
Me.MousePointer = 8
SizeMode = 7
Else
Me.MousePointer = 9
SizeMode = 4
End If
End If
End Sub
Private Sub tmrCheckFocus_Timer()
If GetForegroundWindow = BoundWindow Then
Me.BackColor = fColor
Else
Me.BackColor = nfColor
End If
'-------------------------------------------------
Dim wp As WINDOWPLACEMENT
Dim wRect As RECT
GetWindowPlacement BoundWindow, wp
If wp.ShowCmd = SW_MAXIMIZE Then
Me.Hide
Else
GetWindowRect BoundWindow, wRect
If Me.Visible = False Then
Me.Show
End If
Select Case Pos
Case TopPos
If UseSetParent Then
SetWindowPos Me.hWnd, 0, 0, 0, _
wRect.Right - wRect.Left, Thickness, SWP_NOZORDER Or SWP_NOACTIVATE
Else
SetWindowPos Me.hWnd, 0, wRect.Left - Thickness, wRect.Top - Thickness, _
wRect.Right - wRect.Left + Thickness * 2, Thickness, SWP_NOZORDER Or SWP_NOACTIVATE
End If
Case BottomPos
If UseSetParent Then
SetWindowPos Me.hWnd, 0, 0, wRect.bottom - wRect.Top - Thickness, _
wRect.Right - wRect.Left, Thickness, SWP_NOZORDER Or SWP_NOACTIVATE
Else
SetWindowPos Me.hWnd, 0, wRect.Left - Thickness, wRect.bottom, _
wRect.Right - wRect.Left + Thickness * 2, Thickness, SWP_NOZORDER Or SWP_NOACTIVATE
End If
Case LeftPos
If UseSetParent Then
SetWindowPos Me.hWnd, 0, 0, 0, _
Thickness, wRect.bottom - wRect.Top, SWP_NOZORDER Or SWP_NOACTIVATE
Else
SetWindowPos Me.hWnd, 0, wRect.Left - Thickness, wRect.Top, _
Thickness, wRect.bottom - wRect.Top, SWP_NOZORDER Or SWP_NOACTIVATE
End If
Case RightPos
If UseSetParent Then
SetWindowPos Me.hWnd, 0, wRect.Right - wRect.Left - Thickness, 0, _
Thickness, wRect.bottom - wRect.Top, SWP_NOZORDER Or SWP_NOACTIVATE
Else
SetWindowPos Me.hWnd, 0, wRect.Right, wRect.Top, _
Thickness, wRect.bottom - wRect.Top, SWP_NOZORDER Or SWP_NOACTIVATE
End If
End Select
If GetAsyncKeyState(VK_LBUTTON) = 0 Then
ClipCursor ByVal 0
bMoving = False
End If
If bMoving Then
Dim cur As POINT
Dim ParentWindow As Long
Dim ParentRect As RECT
GetCursorPos cur
ParentWindow = GetPropA(BoundWindow, "Parent")
If ParentWindow <> 0 Then
GetWindowRect ParentWindow, ParentRect
End If
Select Case SizeMode
Case 0
If ParentWindow = 0 Then
If cur.X < PrevRect.Right Then
NewX = cur.X
NewW = PrevRect.Right - cur.X
End If
If cur.Y < PrevRect.bottom Then
NewY = cur.Y
NewH = PrevRect.bottom - cur.Y
End If
If NewW < MinW Then
NewW = MinW
NewX = PrevRect.Right - NewW
End If
If NewH < MinH Then
NewH = MinH
NewY = PrevRect.bottom - NewH
End If
Else
If cur.X < PrevRect.Right Then
NewX = cur.X - ParentRect.Left
NewW = PrevRect.Right - cur.X
End If
If cur.Y < PrevRect.bottom Then
NewY = cur.Y - ParentRect.Top
NewH = PrevRect.bottom - cur.Y
End If
If NewW < MinW Then
NewW = MinW
NewX = PrevRect.Right - NewW - ParentRect.Left
End If
If NewH < MinH Then
NewH = MinH
NewY = PrevRect.bottom - NewH - ParentRect.Top
End If
End If
Case 1
If ParentWindow = 0 Then
NewX = PrevRect.Left
NewW = PrevRect.Right - PrevRect.Left
If cur.Y < PrevRect.bottom Then
NewY = cur.Y
NewH = PrevRect.bottom - cur.Y
End If
If NewH < MinH Then
NewH = MinH
NewY = PrevRect.bottom - NewH
End If
Else
NewX = PrevRect.Left
NewW = PrevRect.Right - PrevRect.Left - ParentRect.Left
If cur.Y < PrevRect.bottom Then
NewY = cur.Y - ParentRect.Top
NewH = PrevRect.bottom - cur.Y
End If
If NewH < MinH Then
NewH = MinH
NewY = PrevRect.bottom - NewH - ParentRect.Top
End If
End If
Case 2
If ParentWindow = 0 Then
NewX = PrevRect.Left
If cur.X > PrevRect.Left Then
NewW = cur.X - PrevRect.Left
End If
If cur.Y < PrevRect.bottom Then
NewY = cur.Y
NewH = PrevRect.bottom - cur.Y
End If
If NewW < MinW Then
NewW = MinW
End If
If NewH < MinH Then
NewH = MinH
NewY = PrevRect.bottom - NewH
End If
Else
NewX = PrevRect.Left
If cur.X > PrevRect.Left Then
NewW = cur.X - PrevRect.Left - ParentRect.Left
End If
If cur.Y < PrevRect.bottom Then
NewY = cur.Y - ParentRect.Top
NewH = PrevRect.bottom - cur.Y
End If
If NewW < MinW Then
NewW = MinW
End If
If NewH < MinH Then
NewH = MinH
NewY = PrevRect.bottom - NewH - ParentRect.Top
End If
End If
Case 3
If ParentWindow = 0 Then
If cur.X < PrevRect.Right Then
NewX = cur.X
NewW = PrevRect.Right - cur.X
End If
NewY = PrevRect.Top
NewH = PrevRect.bottom - PrevRect.Top
If NewW < MinW Then
NewW = MinW
NewX = PrevRect.Right - NewW
End If
Else
If cur.X < PrevRect.Right Then
NewX = cur.X - ParentRect.Left
NewW = PrevRect.Right - cur.X
End If
NewY = PrevRect.Top
NewH = PrevRect.bottom - PrevRect.Top - ParentRect.Top
If NewW < MinW Then
NewW = MinW
NewX = PrevRect.Right - NewW - ParentRect.Left
End If
End If
Case 4
If ParentWindow = 0 Then
NewX = PrevRect.Left
If cur.X > PrevRect.Left Then
NewW = cur.X - PrevRect.Left
End If
NewY = PrevRect.Top
NewH = PrevRect.bottom - PrevRect.Top
If NewW < MinW Then
NewW = MinW
End If
Else
NewX = PrevRect.Left
If cur.X > PrevRect.Left Then
NewW = cur.X - PrevRect.Left - ParentRect.Left
End If
NewY = PrevRect.Top
NewH = PrevRect.bottom - PrevRect.Top - ParentRect.Top
If NewW < MinW Then
NewW = MinW
End If
End If
Case 5
If ParentWindow = 0 Then
If cur.X < PrevRect.Right Then
NewX = cur.X
NewW = PrevRect.Right - cur.X
End If
NewY = PrevRect.Top
If cur.Y > PrevRect.Top Then
NewH = cur.Y - PrevRect.Top
End If
If NewW < MinW Then
NewW = MinW
NewX = PrevRect.Right - NewW
End If
If NewH < MinH Then
NewH = MinH
End If
Else
If cur.X < PrevRect.Right Then
NewX = cur.X - ParentRect.Left
NewW = PrevRect.Right - cur.X
End If
NewY = PrevRect.Top
If cur.Y > PrevRect.Top Then
NewH = cur.Y - PrevRect.Top - ParentRect.Top
End If
If NewW < MinW Then
NewW = MinW
NewX = PrevRect.Right - NewW - ParentRect.Left
End If
If NewH < MinH Then
NewH = MinH
End If
End If
Case 6
If ParentWindow = 0 Then
NewX = PrevRect.Left
NewW = PrevRect.Right - PrevRect.Left
NewY = PrevRect.Top
If cur.Y > PrevRect.Top Then
NewH = cur.Y - PrevRect.Top
End If
If NewH < MinH Then
NewH = MinH
End If
Else
NewX = PrevRect.Left
NewW = PrevRect.Right - PrevRect.Left - ParentRect.Left
NewY = PrevRect.Top
If cur.Y > PrevRect.Top Then
NewH = cur.Y - PrevRect.Top - ParentRect.Top
End If
If NewH < MinH Then
NewH = MinH
End If
End If
Case 7
If ParentWindow = 0 Then
NewX = PrevRect.Left
If cur.X > PrevRect.Left Then
NewW = cur.X - PrevRect.Left
End If
NewY = PrevRect.Top
If cur.Y > PrevRect.Top Then
NewH = cur.Y - PrevRect.Top
End If
If NewW < MinW Then
NewW = MinW
End If
If NewH < MinH Then
NewH = MinH
End If
Else
NewX = PrevRect.Left
If cur.X > PrevRect.Left Then
NewW = cur.X - PrevRect.Left - ParentRect.Left
End If
NewY = PrevRect.Top
If cur.Y > PrevRect.Top Then
NewH = cur.Y - PrevRect.Top - ParentRect.Top
End If
If NewW < MinW Then
NewW = MinW
End If
If NewH < MinH Then
NewH = MinH
End If
End If
End Select
SetWindowPos BoundWindow, 0, NewX, NewY, NewW, NewH, SWP_NOZORDER
End If
End If
End Sub