'in a module
Option Explicit
Public Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" _
(ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Function TrimNull(startstr As String) As String
Dim pos As Integer
pos = InStr(startstr, Chr$(0))
If pos Then
TrimNull = Left$(startstr, pos - 1)
Exit Function
End If
TrimNull = startstr
End Function
Private Function GetWindowIdentification(ByVal hwnd As Long, _
sIDType As String, sClass As String) As String
Dim nSize As Long
Dim sTitle As String
nSize = GetWindowTextLength(hwnd)
'if the return is 0, there is no title
If nSize > 0 Then
sTitle = Space$(nSize + 1)
Call GetWindowText(hwnd, sTitle, nSize + 1)
sIDType = "title"
sClass = Space$(64)
Call GetClassName(hwnd, sClass, 64)
Else
'no title, so get the class name instead
sTitle = Space$(64)
Call GetClassName(hwnd, sTitle, 64)
sClass = sTitle
sIDType = "class"
End If
GetWindowIdentification = TrimNull(sTitle)
End Function
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sTitle As String
Dim sClass As String
Dim sIDType As String
'get the window title/class name
sTitle = GetWindowIdentification(hwnd, sIDType, sClass)
'add to our list
Form1.List1.AddItem sTitle & ": Hwnd=" & hwnd & ", Class=" & TrimNull(sClass) & ", IDType=" & sIDType
EnumChildProc = 1
End Function
'in the form
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_SETTEXT = &HC
Private Const BM_CLICK = &HF5
Private Const WM_SETFOCUS = &H7
Private Sub Command1_Click()
Dim Lhwnd As Long
List1.Clear
' get hwnd to our dialog/program window
Lhwnd = FindWindow(vbNullString, "Login to NetZero")
If Lhwnd Then ' get childs
Call EnumChildWindows(Lhwnd, AddressOf EnumChildProc, &H0)
End If
End Sub
Private Sub Command2_Click()
Text1.Text = List1.List(4)
End Sub
Private Sub Command3_Click()
Call SendMessageByString(Text1.Text, WM_SETTEXT, 0, "portland")
End Sub
Private Sub Form_Load()
End Sub
Private Sub Text1_Change()
Text1.Text = Replace(Text1.Text, "zuicombobox: Hwnd=", "")
Text1.Text = Replace(Text1.Text, ", Class=zuicombobox, IDType=class", "")
End Sub