'Form1.frm 文件
'--------------
Option Explicit
Private Sub Command1_Click()
List1.Clear
EnumWindows AddressOf EnumProc, 0
If List1.ListCount = 0 Then List1.AddItem "没有启动 IE 浏览器"
End Sub
'Module1.bas 文件
'---------------
Option Explicit
'相关 API 函数声明
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam 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 '取得指定窗口的司法题
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 GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long '取得窗口句柄
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, lParam As Any) As Long '发送消息
'遍查主窗口
Public Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
Dim buf As String * 1024
Dim length As Long
Dim title As String
length = GetWindowText(app_hwnd, buf, Len(buf))
title = Left$(buf, length)
'判断是否为 IE 浏览器窗口
If InStr(title, " - Netscape") Or InStr(title, " - Microsoft Internet Explorer") Or InStr(title, "Offline Explorer") Then
Call GetZiWin(app_hwnd)
End If
EnumProc = 1
End Function
'遍查子窗口
Public Function GetZiWin(window_hwnd As Long) As String
Dim buf As String
Dim buflen As Long
Dim child_hwnd As Long
Dim children() As Long
Dim num_children As Integer
Dim i As Integer