' ****** Constants & Declarations Dealing with Running Tasks ********** Public Const GW_HWNDNEXT = 2 '\2 = next window handle
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" _
(ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
' *** This function checks if a task exists by searching for (part or all of) the window title.
Public Function TaskExists(ByVal strCheckTask As String, ByVal ExactMatch As Boolean) As Boolean
' ****** Declare Variables ************ Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
' ********** Initialize Variables ******** TaskExists = False
CurrWnd = GetActiveWindow()
' ************************************** Do While (CurrWnd <> 0)
Length = GetWindowTextLength(CurrWnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(CurrWnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)
If (Length > 0) Then
If ExactMatch = True Then 'task gelijk aan string
If (TaskName = strCheckTask) Then
TaskExists = True
Exit Do
End If
Else
If InStr(TaskName, strCheckTask) Then
TaskExists = True
Exit Do
End If
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Loop
End Function