by Dennis Middeljans (2 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 28th January 2002
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Check for a running program...
API Declarations
"FindWindowA" (ByVal strClass As String, _
ByVal lpWindow As String) As Long
Public Declare Function apiSendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal _
wParam As Long, lParam As Long) As Long
Public Declare Function apiIsIconic Lib "user32" Alias _
"IsIconic" (ByVal hwnd As Long) As Long
Public Declare Function apiShowWindow Lib "user32" Alias _
"ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function apiSetForegroundWindow Lib "user32" Alias _
"SetForegroundWindow" (ByVal hwnd As Long) As Long
Optional fActivate As Boolean) As Boolean
'Example : fIsAppRunning("Excel")
Dim lngH As Long, strClassName As String
Dim lngX As Long, lngTmp As Long
Const WM_USER = 1024
On Local Error GoTo fIsAppRunning_Err
fIsAppRunning = False
Select Case LCase$(strAppName)
Case "excel": strClassName = "XLMain"
Case "word": strClassName = "OpusApp"
Case "access": strClassName = "OMain"
Case "powerpoint95": strClassName = "PP7FrameClass"
Case "powerpoint97": strClassName = "PP97FrameClass"
Case "notepad": strClassName = "NOTEPAD"
Case "paintbrush": strClassName = "pbParent"
Case "wordpad": strClassName = "WordPadClass"
Case "Outlook": strClassName = "rctrl_renwnd32"
Case "Jetmark32": strClassName = "PFWMainFrame"
Case "Program Manager": strClassName = "Progman"
Case Else: strClassName = ""
End Select
If strClassName = "" Then
lngH = apiFindWindow(vbNullString, strAppName)
Else
lngH = apiFindWindow(strClassName, vbNullString)
End If
If lngH <> 0 Then
apiSendMessage lngH, WM_USER + 18, 0, 0
lngX = apiIsIconic(lngH)
If lngX <> 0 Then
lngTmp = apiShowWindow(lngH, SW_SHOWNORMAL)
End If
If fActivate Then
lngTmp = apiSetForegroundWindow(lngH)
End If
fIsAppRunning = True
End If
fIsAppRunning_Exit:
Exit Function
fIsAppRunning_Err:
fIsAppRunning = False
Resume fIsAppRunning_Exit
End Function