Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
'//Find the Messenger Window handle
phWnd = FindWindow(0, "Messenger Service ")
'phWnd = FindWindow(0, "Project1")
If phWnd > 0 Then
'//Find the Static Window handle
EnumChildWindows phWnd, AddressOf EnumChildProc, ByVal 0&
End If
End Sub
Public Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim tmp As String
Dim wClass As String
Dim Buff As String
'//Get the Child Class Name
tmp = String(260, Chr(0))
GetClassName hWnd, tmp, 260
p1 = InStr(1, tmp, Chr(0), vbTextCompare)
If p1 > 0 Then
wClass = Left$(tmp, p1 - 1)
'//compare the class name
If StrComp(UCase(wClass), "STATIC", vbTextCompare) = 0 Then
'//Continue retrieve the Message
Buff = Space$(GetWindowTextLength(hWnd) + 1)
GetWindowText hWnd, Buff, Len(Buff)
'//Display the text
Buff = Left$(Buff, Len(Buff) - 1)
MsgBox Buff
Exit Function
End If
End If
'//Continue enumeration
EnumChildProc = 1
End Function