forked from lee-soft/ViPad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskbarHelper.bas
165 lines (123 loc) · 4.92 KB
/
TaskbarHelper.bas
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
Attribute VB_Name = "TaskbarHelper"
Option Explicit
Public g_ReBarWindow32Hwnd As Long
Public g_RunningProgramsHwnd As Long
Public g_StartButtonHwnd As Long
Public g_TaskBarHwnd As Long
Public g_StartMenuHwnd As Long
Public g_StartMenuOpen As Boolean
Public g_viStartRunning As Boolean
Public g_viStartOrbHwnd As Long
Public g_WindowsVista As Boolean
Private m_TargetTaskList As TaskList
Private m_taskbarRect As Win.RECT
Public Function UpdatehWnds() As Boolean
Dim newTaskBarHwnd As Long
Dim updatedHwnd As Boolean
updatedHwnd = False
newTaskBarHwnd = FindWindow("Shell_TrayWnd", "")
If newTaskBarHwnd = 0 Then
Exit Function
End If
If newTaskBarHwnd <> g_TaskBarHwnd Then
g_TaskBarHwnd = newTaskBarHwnd
g_ReBarWindow32Hwnd = FindWindowEx(ByVal g_TaskBarHwnd, ByVal 0&, "ReBarWindow32", vbNullString)
'g_ReBarWindow32Hwnd = FindWindowEx(ByVal FindWindowEx(ByVal g_ReBarWindow32Hwnd, ByVal 0&, "MSTaskSwWClass", "Running Applications"), _
ByVal 0&, "ToolbarWindow32", "Running Applications")
g_RunningProgramsHwnd = FindWindowEx(FindWindowEx(ByVal g_ReBarWindow32Hwnd, ByVal 0&, "MsTaskSwWClass", vbNullString), ByVal 0&, "ToolbarWindow32", vbNullString)
If g_RunningProgramsHwnd = 0 Then
g_RunningProgramsHwnd = FindWindowEx(FindWindowEx(ByVal g_ReBarWindow32Hwnd, ByVal 0&, "MSTaskSwWClass", vbNullString), ByVal 0&, "MSTaskListWClass", vbNullString)
If g_RunningProgramsHwnd = 0 Then
'Reset update trigger (forcing routine to later update again)
g_TaskBarHwnd = -1
End If
End If
g_StartButtonHwnd = FindWindowEx(g_TaskBarHwnd, 0, "Button", vbNullString)
If g_StartButtonHwnd = 0 Then
'Windows Vista/Seven
g_StartButtonHwnd = FindWindow("Button", "Start")
If g_StartButtonHwnd = 0 Then
'Reset update trigger (forcing routine to later update again)
g_TaskBarHwnd = -1
Else
g_WindowsVista = True
End If
End If
updatedHwnd = True
End If
UpdatehWnds = updatedHwnd
End Function
Function IsTaskBarBehindWindow(hWnd As Long)
If GetZOrder(g_TaskBarHwnd) > GetZOrder(hWnd) Then
IsTaskBarBehindWindow = True
Else
IsTaskBarBehindWindow = False
End If
End Function
Function IsWindowTopMost(hWnd As Long)
Dim windowStyle As Long
IsWindowTopMost = False
windowStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
If IsStyle(windowStyle, WS_EX_TOPMOST) Then
IsWindowTopMost = True
End If
End Function
Public Function EnumWindowsAsTaskList(ByRef srcCollection As TaskList)
On Error GoTo Handler
' Clear list, then fill it with the running
' tasks. Return the number of tasks.
'
' The EnumWindows function enumerates all top-level windows
' on the screen by passing the handle of each window, in turn,
' to an application-defined callback function. EnumWindows
' continues until the last top-level window is enumerated or
' the callback function returns FALSE.
'
If Not srcCollection Is Nothing Then
Set m_TargetTaskList = srcCollection
Call EnumWindows(AddressOf fEnumWindowsCallBack, ByVal 0)
End If
Exit Function
Handler:
LogError Err.Number, "EnumerateWindowsAsTaskObject(); " & Err.Description, "TaskbarHelper"
End Function
Public Function fEnumWindowsCallBack(ByVal hWnd As Long, ByVal lParam As Long) As Long
If IsVisibleToTaskBar(hWnd) Then
m_TargetTaskList.AddWindowByHwnd hWnd
End If
fEnumWindowsCallBack = True
End Function
Public Function IsVisibleToTaskBar(hWnd As Long) As Boolean
Dim lReturn As Long
Dim lExStyle As Long
Dim bNoOwner As Boolean
IsVisibleToTaskBar = False
' This callback function is called by Windows (from
' the EnumWindows API call) for EVERY window that exists.
' It populates the listbox with a list of windows that we
' are interested in.
'
' Windows to display are those that:
' - are not this app's
' - are visible
' - do not have a parent
' - have no owner and are not Tool windows OR
' have an owner and are App windows
' can be activated
If IsWindowVisible(hWnd) Then
If (GetParent(hWnd) = 0) Then
bNoOwner = (GetWindow(hWnd, GW_OWNER) = 0)
lExStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
If (((lExStyle And WS_EX_TOOLWINDOW) = 0) And bNoOwner) Or _
((lExStyle And WS_EX_APPWINDOW) And Not bNoOwner) Then
IsVisibleToTaskBar = True
End If
End If
End If
End Function
Public Function IsVisibleOnTaskbar(lExStyle As Long) As Boolean
IsVisibleOnTaskbar = False
If (lExStyle And WS_EX_APPWINDOW) Then
IsVisibleOnTaskbar = True
End If
End Function