-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMenuBarHelper.bas
More file actions
232 lines (152 loc) · 6.81 KB
/
MenuBarHelper.bas
File metadata and controls
232 lines (152 loc) · 6.81 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
Attribute VB_Name = "MenuBarHelper"
'--------------------------------------------------------------------------------
' Component : MenuBarHelper
' Project : ViDock
'
' Description: Containts MenuBar helper functions
'
'--------------------------------------------------------------------------------
Option Explicit
Public Const TEXTMODE_ITEM_Y_GAP As Long = 21
Public Const ITEM_MARGIN_X As Long = 20
Public Const MENU_MARGIN_X As Long = 5
Public Const MENU_MARGIN_Y As Long = 2
Public Const MAX_TITLE_CHARACTERS As Long = 30
Public Function HandleProcessMenuResult(theMenuResult As Long, lastProcess As Process)
Dim szNewShortcutPath As String
Dim szOpenedFileInProcess As String
Select Case theMenuResult
Case 1
lastProcess.MinimizeAllWindows
Case 2
lastProcess.RestoreAllWindows
Case 4
lastProcess.RequestCloseAllWindows
Case 5
If lastProcess.Pinned = False Then
If lastProcess.Path <> vbNullString Then
If Len(lastProcess.Arguments) > 0 Then
szOpenedFileInProcess = StrEnd(lastProcess.Arguments, "\")
szNewShortcutPath = Environ("appdata") & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\" & lastProcess.Caption & " - " & szOpenedFileInProcess & ".lnk"
Else
szNewShortcutPath = Environ("appdata") & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\" & lastProcess.Caption & ".lnk"
End If
If CreateShortcut(szNewShortcutPath, lastProcess.Path, lastProcess.Arguments) Then
lastProcess.PhysicalLinkFile = szNewShortcutPath
lastProcess.Pinned = True
End If
Else
LogError -2, "Invalid path; Null", "TaskBar"
End If
Else
lastProcess.Pinned = False
If FileExists(lastProcess.PhysicalLinkFile) Then
On Error GoTo Handler
Kill lastProcess.PhysicalLinkFile
Handler:
End If
'ViGlance
'SortPinnedList
'DumpOptions
'RemoveFromPinnedList m_lastHoveredGroup.Path
End If
End Select
End Function
Public Function GetWindowTextByhWnd(ByVal hWnd As Long) As String
Dim lReturn As Long
Dim windowTitle As String
windowTitle = Space$(256)
lReturn = GetWindowText(hWnd, windowTitle, Len(windowTitle))
If lReturn Then
windowTitle = Left$(windowTitle, lReturn)
If Len(windowTitle) > MAX_TITLE_CHARACTERS Then
windowTitle = Left(windowTitle, MAX_TITLE_CHARACTERS) & "... "
End If
End If
GetWindowTextByhWnd = windowTitle
End Function
Private Function HandleSubMenu(ByRef theMenuItem As MenuItem, _
ByRef sourceMenu As ListMenu, _
ByVal theItemPosition As Long)
If Not sourceMenu.ChildMenu Is Nothing Then
Unload sourceMenu.ChildMenu
End If
Set sourceMenu.ChildMenu = New ListMenu
Set sourceMenu.ChildMenu.ParentMenu = sourceMenu
sourceMenu.ChildMenu.ShowList theMenuItem.Children, (sourceMenu.Top + ((theItemPosition * TEXTMODE_ITEM_Y_GAP) * Screen.TwipsPerPixelY)) - 45 * Screen.TwipsPerPixelY, (sourceMenu.Left / Screen.TwipsPerPixelX) + sourceMenu.ScaleWidth, vbPopupMenuLeftAlign, False, True
End Function
Public Function HandleMenuItemHovered(ByRef theMenuItem As MenuItem, _
ByRef sourceMenu As ListMenu, _
ByVal theItemPosition As Long, _
ByRef closeCallerMenu As Boolean)
If theMenuItem.Children.Count > 0 Then
HandleSubMenu theMenuItem, sourceMenu, theItemPosition
closeCallerMenu = False
Exit Function
Else
If Not sourceMenu.ChildMenu Is Nothing Then
sourceMenu.ChildMenu.closeMe
Set sourceMenu.ChildMenu = Nothing
End If
End If
End Function
Public Function HandleMenuItem(ByRef theMenuItem As MenuItem, _
ByRef sourceMenu As ListMenu, _
ByVal theItemPosition As Long, _
ByRef closeCallerMenu As Boolean)
If theMenuItem.Children.Count > 0 Then
HandleSubMenu theMenuItem, sourceMenu, theItemPosition
closeCallerMenu = False
Exit Function
End If
PostMessage theMenuItem.hWnd, ByVal WM_COMMAND, ByVal theMenuItem.itemID, ByVal 0
closeCallerMenu = True
End Function
Public Function PopulateMenuFromHandle(ByRef theMenuRoot As Collection, _
ByVal hMenu As Long, _
ByVal hWnd As Long)
Dim num As Long
Dim itemIndex As Long
Dim thisMenuItem As MenuItem
Dim hSubMenu As Long
Dim szCaption As String
Dim captionLength As Long
Dim tabPosition As Long
num = GetMenuItemCount(hMenu)
If num > -1 Then Debug.Print "MenuCount:: " & num
For itemIndex = 0 To num - 1
Set thisMenuItem = New MenuItem
hSubMenu = GetSubMenu(hMenu, itemIndex)
szCaption = Space(256)
captionLength = GetMenuString(hMenu, itemIndex, szCaption, Len(szCaption), MF_BYPOSITION)
szCaption = Replace(Left$(szCaption, captionLength), "&", "")
tabPosition = InStrRev(szCaption, vbTab)
If tabPosition > 0 Then
szCaption = Mid(szCaption, 1, tabPosition)
End If
thisMenuItem.Caption = szCaption
thisMenuItem.itemID = GetMenuItemID(hMenu, itemIndex)
thisMenuItem.hWnd = hWnd
theMenuRoot.Add thisMenuItem
PopulateMenuFromHandle thisMenuItem.Children, hSubMenu, hWnd
Next
End Function
Private Sub GetMenuInfo(hMenu As Long, spaces As Integer, txt As String)
Dim num As Integer
Dim i As Integer
Dim length As Long
Dim sub_hmenu As Long
Dim sub_name As String
num = GetMenuItemCount(hMenu)
For i = 0 To num - 1
' Save this menu's info.
sub_hmenu = GetSubMenu(hMenu, i)
Debug.Print GetMenuItemID(hMenu, i)
sub_name = Space$(256)
length = GetMenuString(hMenu, i, sub_name, Len(sub_name), MF_BYPOSITION)
sub_name = Left$(sub_name, length)
txt = txt & Space$(spaces) & sub_name & vbCrLf
' Get its child menu's names.
GetMenuInfo sub_hmenu, spaces + 4, txt
Next i
End Sub