模块中:
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowEnabled Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim strclsname As String, str1 As String, l As Long, h1 As Long, h2 As Long
strclsname = Space(255)
str1 = Space(255)
l = GetClassName(hwnd, strclsname, Len(strclsname))
h1 = IsWindowVisible(hwnd)
h2 = IsWindowEnabled(hwnd)
If Left(strclsname, l) <> "" Then Form1.List1.AddItem Left(strclsname, l) & ":" & IIf(h1, "Visible", "Invisible") & "," & IIf(h2, "Enable", "Disable")
'continue enumeration
EnumChildProc = 1
End Function
form中:
Private Sub Command1_Click()
Dim h As Long, l As Long, strclsname As String, strwndname As String
strclsname = vbNullString
strwndname = "!@#$%^&"'你要找的窗口名
h = FindWindow(strclsname, strwndname)
EnumChildWindows h, AddressOf EnumChildProc, ByVal 0&
End Sub