Private Function FindProg() As Boolean
Dim lClientHandle As Integer
Dim lH As Integer
Dim lH2 As Integer
Dim tWin1 As Integer
Dim x As Integer
Dim st1 As String
Dim stBuilder As New System.Text.StringBuilder(256)
Try
'Get the top level window using the window caption.
p3Handle = FindWindow(vbNullString, "PITTag3 - [New Tag Session]")
If p3Handle = 0 Then
'This is another possibility.
p3Handle = FindWindow(vbNullString, "PITTag3")
If p3Handle = 0 Then
'This is an attempt to find the registered class.
p3Handle = FindWindow("ThunderRT6MDIForm", vbNullString)
If p3Handle > 0 Then
x = GetWindowText(p3Handle, stBuilder, stBuilder.Capacity + 1)
'This would be the right one.
st1 = stBuilder.ToString
If Not st1.Substring(0, 7) = "PITTag3" Then
mErrorMessage = "Some other program is blocking the visibility of P3."
Return False
End If
End If
End If
End If
If p3Handle > 0 Then
'The rest of these lines drill down through the many layers of client windows
'to get the handle of the base window.
lClientHandle = FindWindowEx(p3Handle, 0, "MDIClient", vbNullString)
lH2 = FindWindowEx(lClientHandle, 0, "ThunderRT6FormDC", vbNullString)
If lH2 = 0 Then
mErrorMessage = "There is no session open. Try this again after opening a session."
Return False
End If
lH = FindWindowEx(lH2, 0, vbNullString, vbNullString)
lH2 = FindWindowEx(lH, 0, vbNullString, vbNullString)
lH2 = FindWindowEx(lH, lH2, vbNullString, vbNullString)
tWin1 = FindWindowEx(lH2, 0, "ATLfpOCXComboBox30", vbNullString)
For x = 1 To 3
tWin1 = FindWindowEx(lH2, tWin1, "ATLfpOCXComboBox30", vbNullString)
Next
'This is the proper window, so use it.
p3TextHandle = FindWindowEx(lH2, tWin1, "ATLfpOCXComboBox30", vbNullString)
If p3TextHandle = 0 Then
mErrorMessage = "Unable to find the correct textbox. This is hard to explain, but if you get this message, there is still a bug remaining to be squashed."
Return False
Else
Return True
End If
Else
mErrorMessage = "P3 could not be located. It may not be running, or some unforseen situation has arisen."
Return False
End If
Catch ex As Exception
mErrorMessage = ex.Message
Return False
End Try
End Function