I am trying to test for an open window using findwindow but I always get a value returned in the hwnd variable whether the app is open or not. I have tried putting garbage in for the caption name and it still returns numbers. All the info out there on find window indicates that if the window you are testing for is closed, it should return 0 but I can't get it to return 0. Any help is appreciated, here is the code.
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hwnd As Long
hwnd = FindWindow("XLMAIN", 0)
If hwnd <> 0 Then
MessageBox.Show("The window handle is " & hwnd)
Else
MessageBox.Show("the app is not running"
End If
End Sub
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hwnd As Long
hwnd = FindWindow("XLMAIN", 0)
If hwnd <> 0 Then
MessageBox.Show("The window handle is " & hwnd)
Else
MessageBox.Show("the app is not running"
End If
End Sub