by BattleStar-Galactica » Fri Feb 17, 2006 12:24 am
try this one:
' public declaration in your form1
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer
Public Delegate Function MyDelegateCallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
Declare Function EnumWindows Lib "user32" (ByVal x As MyDelegateCallBack, ByVal y As Integer) As Integer
Dim wndtitle As String
'function to evaluate the output of enumwindows
Public Function EnumOutput(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
Dim length As Integer = GetWindowTextLength(hwnd)
Dim sb As String = Space(length)
GetWindowText(hwnd, sb, length + 25)
If sb.Length < 1 Then
Return True
End If
Dim title As String = sb.ToString()
If title <> "" Then
If title.IndexOf("Voice Room") > -1 Then
wndtitle = title
MessageBox.Show(title)
Return False 'stop find next window
End If
End If
Return True
End Function
'and call the api function in the button click
EnumWindows(AddressOf EnumOutput, 0)
' the result will store in a variable wndtitle