先去得这两个窗体的句柄,在用GetTopWindow取得子窗体的句柄。比较判断 GetTopWindow : Public Declare Function GetTopWindow Lib "user32" Alias "GetTopWindow" (ByVal hwnd As Long) As Long 搜索内部窗口列表,寻找隶属于指定窗口的头一个窗口的句柄。
用EnumWindows和GetWindowText 取的窗口标题比较应该可以吧
EnumChildWindows 为指定的父窗口枚举子窗口 EnumWindows 枚举窗口列表中的所有父窗口 'in a form Private Sub Form_Load() Me.AutoRedraw = True EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0& End Sub 'in a module Declare Function GetDesktopWindow Lib "user32" () As Long Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long Dim sSave As String 'Get the windowtext length sSave = Space$(GetWindowTextLength(hwnd) + 1) 'get the window text GetWindowText hwnd, sSave, Len(sSave) 'remove the last Chr$(0) sSave = Left$(sSave, Len(sSave) - 1) If sSave <> "" Then Form1.Print sSave 'continue enumeration EnumChildProc = 1 End Function
GetTopWindow :
Public Declare Function GetTopWindow Lib "user32" Alias "GetTopWindow" (ByVal hwnd As Long) As Long
搜索内部窗口列表,寻找隶属于指定窗口的头一个窗口的句柄。
EnumWindows 枚举窗口列表中的所有父窗口
'in a form
Private Sub Form_Load()
Me.AutoRedraw = True
EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0&
End Sub
'in a module
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength(hwnd) + 1)
'get the window text
GetWindowText hwnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave <> "" Then Form1.Print sSave
'continue enumeration
EnumChildProc = 1
End Function