Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a program is running now or not by its title ? (using vb6)

Tags:

process

vb6

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

alt text

like image 711
faressoft Avatar asked Dec 15 '25 10:12

faressoft


2 Answers

''# 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.

like image 67
Tomalak Avatar answered Dec 17 '25 01:12

Tomalak


Karl Peterson has some great code for this on his excellent VB6 website. It uses EnumWindows like Tomalak's answer (in the link)

like image 32
MarkJ Avatar answered Dec 17 '25 00:12

MarkJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!