-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathWindowListHelper.bas
More file actions
316 lines (195 loc) · 7.93 KB
/
WindowListHelper.bas
File metadata and controls
316 lines (195 loc) · 7.93 KB
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
Attribute VB_Name = "MenuListHelper"
'--------------------------------------------------------------------------------
' Component : MenuListHelper
' Project : ViDock
'
' Description: Unused code from ViGlance. Helper functions for rendering
' the window captions on a process
'
'--------------------------------------------------------------------------------
Option Explicit
Private Const ButtonUnpressedId As String = "unpressed"
Private Const ButtonPressedId As String = "pressed"
Private Const ButtonNoticeId As String = "notice"
Private Const ButtonOverId As String = "over"
Public Enum ButtonState
ButtonPressed = 1
ButtonUnpressed = 2
ButtonNotice = 3
ButtonOver = 4
End Enum
Public Function IsMyAncestor(hWnd As Long) As Boolean
Dim theForm As Form
IsMyAncestor = False
Set theForm = GetFormByhWnd(hWnd)
If theForm Is Nothing Then
Exit Function
End If
If theForm.Name = "ListMenu" Then
IsMyAncestor = True
End If
End Function
Public Function HandleWindow(hWnd As Long)
Dim currWinP As WINDOWPLACEMENT
Dim MousePosition As Win.POINTL
Dim windowPos As Win.RECT
If IsWindowHung(hWnd) Then Exit Function
Call GetCursorPos(MousePosition)
If GetWindowPlacement(hWnd, currWinP) > 0 Then
If (currWinP.ShowCmd = SW_SHOWMINIMIZED) Then
'minimized, so restore
ShowWindow hWnd, SW_RESTORE
g_hwndForeGroundWindow = hWnd
SetForegroundWindow hWnd
GetWindowRect hWnd, windowPos
'repaint?
MoveWindow hWnd, windowPos.Left, windowPos.Top, windowPos.Right - windowPos.Left + 1, windowPos.Bottom - windowPos.Top + 1, ByVal APITRUE
MoveWindow hWnd, windowPos.Left, windowPos.Top, windowPos.Right - windowPos.Left, windowPos.Bottom - windowPos.Top, ByVal APITRUE
ElseIf g_hwndForeGroundWindow = hWnd Then
'normal, so minimize
'AnimateWindow hwnd, 2000, AW_CENTER Or AW_HIDE
ShowWindow hWnd, SW_MINIMIZE
Else
SetForegroundWindow hWnd
End If
End If
End Function
Public Function HandleListFile(ByRef theFile As ListFile)
On Error GoTo Handler
Shell "explorer.exe " & """" & theFile.Path & """"
Exit Function
Handler:
End Function
Public Function GetStackContents(ByVal szStackSpec As String) As Collection
If Right(szStackSpec, 1) <> "\" Then
szStackSpec = szStackSpec & "\"
End If
Dim thisList As Collection
Set thisList = New Collection
Dim theFile As ListFile
Dim theFileName As String
theFileName = Dir(szStackSpec)
Do While theFileName > ""
If theFileName <> vbNullString Then
Set theFile = New ListFile
theFile.Caption = theFileName
theFile.Path = szStackSpec & theFileName
thisList.Add theFile
End If
theFileName = Dir()
Loop
Set GetStackContents = thisList
End Function
Public Function DrawButtonF(ByRef theButton As Collection, _
ByVal theState As ButtonState, _
ByRef Graphics As GDIPGraphics, _
targetRect As gdiplus.RECTF)
'On Error GoTo Handler:
Dim sliceCollection As Collection
Select Case theState
Case ButtonUnpressed
Set sliceCollection = theButton(ButtonUnpressedId)
Case ButtonPressed
Set sliceCollection = theButton(ButtonPressedId)
Case ButtonNotice
Set sliceCollection = theButton(ButtonNoticeId)
Case ButtonOver
Set sliceCollection = theButton(ButtonOverId)
End Select
If Not sliceCollection Is Nothing Then
DrawSlicesToTargetF sliceCollection, Graphics, targetRect
End If
Exit Function
Handler:
LogError 0, "DrawButtonF", "MenuListHelper", Err.Description
End Function
Public Function DrawButton(ByRef theButton As Collection, _
ByVal theState As ButtonState, _
ByRef Graphics As GDIPGraphics, _
targetRect As gdiplus.RECTL)
'On Error GoTo Handler:
Dim sliceCollection As Collection
Select Case theState
Case ButtonUnpressed
Set sliceCollection = theButton(ButtonUnpressedId)
Case ButtonPressed
Set sliceCollection = theButton(ButtonPressedId)
Case ButtonNotice
Set sliceCollection = theButton(ButtonNoticeId)
Case ButtonOver
Set sliceCollection = theButton(ButtonOverId)
End Select
If Not sliceCollection Is Nothing Then
DrawSlicesToTarget sliceCollection, Graphics, targetRect
End If
Handler:
End Function
Public Function CreateButtonFromXML(ByVal szXmlElementName As String, _
ByRef slicesImage As GDIPImage) As Collection
Dim buttonXMlElement As IXMLDOMElement
Dim thisXMLNode As IXMLDOMElement
Dim sliceIndex As IXMLDOMElement
Dim buttonStateImage As GDIPImage
Dim state As gdiplus.RECTL
Dim thisButton As Collection
Dim buttonSlices As Collection
Dim szButtonIdentifier As String
Set buttonXMlElement = ThemeHelper.GetButton(szXmlElementName)
If buttonXMlElement Is Nothing Then
LogError 0, "CreateButtonFromXML", "MenuListHelper", "Warning unable to load button: " & szXmlElementName
Exit Function
End If
Set slicesImage = New GDIPImage
slicesImage.FromFile App.Path & "\resources\" & buttonXMlElement.getAttribute("src")
Set thisButton = New Collection
For Each thisXMLNode In buttonXMlElement.childNodes
If thisXMLNode.tagName = "slice_index" Then
Set sliceIndex = thisXMLNode.cloneNode(True)
End If
Next
If sliceIndex Is Nothing Then
MsgBox "No slice index defined - unable to create button from XML!", vbCritical
Exit Function
End If
For Each thisXMLNode In buttonXMlElement.childNodes
If thisXMLNode.tagName = "state" Then
If Not IsNull(thisXMLNode.getAttribute("id")) Then
szButtonIdentifier = CStr(thisXMLNode.getAttribute("id"))
End If
state.Left = CLng(thisXMLNode.getAttribute("x"))
state.Top = CLng(thisXMLNode.getAttribute("y"))
state.Width = CLng(thisXMLNode.getAttribute("width"))
state.Height = CLng(thisXMLNode.getAttribute("height"))
Set buttonStateImage = CreateNewImageFromSection(slicesImage, state)
Set buttonSlices = CreateSlicesFromXMLElement(sliceIndex, buttonStateImage)
If szButtonIdentifier <> vbNullString Then
thisButton.Add buttonSlices, szButtonIdentifier
End If
End If
Next
Set CreateButtonFromXML = thisButton
End Function
Public Function FindMaxHeight(ByRef ListMenu As Collection, ByVal itemDifference As Long)
On Error GoTo Handler
FindMaxHeight = ListMenu.Count * itemDifference
Handler:
Exit Function
End Function
Public Function FindMaxWidth(ByRef ListMenu As Collection, _
ByRef theGraphics As GDIPGraphics, _
ByRef theFont As GDIPFont)
On Error GoTo Handler
Dim thisItem As Object
Dim lpRect As gdiplus.RECTF
Dim maxWidth As Long
For Each thisItem In ListMenu
lpRect = theGraphics.MeasureString(thisItem.Caption, theFont)
Debug.Print lpRect.Width
If lpRect.Width > maxWidth Then
maxWidth = lpRect.Width
End If
Next
FindMaxWidth = maxWidth
Handler:
Exit Function
End Function