给你个参考代码,n年前写的,忘记干什么用的了,有龌龊只处自己改吧。
Option Explicit
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam 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 Declare Function SendMessageS 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_GETTEXT = &HD
Private hWnd As Long
Private ClassName As String, WindowName As String
Private ReVal As Boolean, IncFind As Boolean
Public Enuming As Boolean
Private Function EnumChildWindow(ByVal hWndChild As Long, ByVal lParam As Long) As Long
Dim lpClassName As String, lpWindowName As String
Dim i As Integer
If ClassName <> vbNullString And WindowName <> vbNullString Then
If Not IncFind Then
If ClassName = lpClassName And WindowName = lpWindowName Then hWnd = hWndChild: ReVal = True: Exit Function
Else
If InStr(1, lpClassName, ClassName, vbTextCompare) > 0 And _
InStr(1, lpWindowName, WindowName, vbTextCompare) > 0 Then hWnd = hWndChild: ReVal = True: Exit Function
End If
ElseIf ClassName <> vbNullString And WindowName = vbNullString Then
If Not IncFind Then
If ClassName = lpClassName Then hWnd = hWndChild: ReVal = True: Exit Function
Else
If InStr(1, lpClassName, ClassName, vbTextCompare) > 0 Then hWnd = hWndChild: ReVal = True: Exit Function
End If
ElseIf ClassName = vbNullString And WindowName <> vbNullString Then
If Not IncFind Then
If WindowName = lpWindowName Then hWnd = hWndChild: ReVal = True: Exit Function
Else
If InStr(1, lpWindowName, WindowName, vbTextCompare) > 0 Then hWnd = hWndChild: ReVal = True: Exit Function
End If
End If
EnumChildWindow = 1
End Function
Public Function GetChildWindow(hWndParent As Long, Optional ByVal lpClassName As String, Optional ByVal lpWindowName As String, Optional Include As Boolean) As Long
lpClassName = UCase(Trim(lpClassName))
lpWindowName = UCase(Trim(lpWindowName))
ClassName = lpClassName
WindowName = lpWindowName
IncFind = Include
EnumChildWindows hWndParent, AddressOf EnumChildWindow, 0
If ReVal Then GetChildWindow = hWnd
Enuming = False
End Function