How to check if a program is running now or not by its title ? (using vb6)
Example :
'check if there is a program contain a "Notepad" in its title
if (does "Notepad" running now ?) then
end if

''# preparation (in a separate module)
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Function FindWindowHandle(Caption As String) As Long
FindWindowHandle = FindWindow(vbNullString, Caption)
End Function
''# use (anywhere)
MsgBox FindWindowHandle("Untitled - Notepad")
Code above basically taken from here.
The exact window caption must be known for this. The function will return <> 0 if a window with the given caption was found, 0 otherwise.
To find a window whose caption contains a certain string, you will need to enumerate all windows and look for the correct one yourself. This process is a little more complicated, but explained in great detail here: everythingaccess.com - Bring an external application window to the foreground.
Karl Peterson has some great code for this on his excellent VB6 website. It uses EnumWindows like Tomalak's answer (in the link)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With