First parameter to the FindWindow API

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

I need to check whether an application is executing. I do not know the class
name of the application; however, I know the window caption of the
application. What would be the first parameter that I should be passing to
the FindWindow API, in order to check whether the application is executing?

Thanks.
kd
 
kd said:
I need to check whether an application is executing. I do not know the
class
name of the application; however, I know the window caption of the
application. What would be the first parameter that I should be passing to
the FindWindow API, in order to check whether the application is
executing?

Simply pass 'vbNullString' to the first parameter and pass the window title
to the second parameter.
 
Just extending what Mr MVP said:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer

' Find Window passing the class name only
Dim intHandle As Integer = FindWindow("[Class Name Here]",
vbNullString)
' Show the handle in a messagebox
MessageBox.Show(intHandle, "Find Window Handle via class name")
' Find Window passing the Window caption only
Dim intHandle2 As Integer = FindWindow(vbNullString, "[Window
Caption Here]")
' Show the handle in a messagebox
MessageBox.Show(intHandle2, "Find Window Handle via Window caption")
 
Crouchie,

Crouchie1998 said:
Just extending what Mr MVP said:

:-)

I would be glad if you don't always call me "Mr MVP" :-). My name is
Herfried...
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer

' Find Window passing the class name only
Dim intHandle As Integer = FindWindow("[Class Name Here]",
vbNullString)

Although your code works, I'd use 'IntPtr' for the handle returned by
'FindWindow' instead of 'Integer'.
 
Back
Top