'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
怎样编程得到当前Web窗口文本信息
Dim dWinFolder As New ShellWindows
Dim WithEvents eventIE As WebBrowser_V1
Private Sub Command1_Click()
Dim objIE As Object
For Each objIE In dWinFolder
If objIE.LocationURL = List1.List(List1.ListIndex) Then
Set eventIE = objIE
Command1.Enabled = False
List1.Enabled = False
Text1.Text = ""
Exit For
End If
Next
End Sub
Private Sub eventIE_NavigateComplete(ByVal URL As String)
Text1.Text = Text1.Text + Chr(13) + Chr(10) + URL
End Sub
在运行前。点击菜单 Projects ¦ References 项,在Available References 列表中选择Microsoft Internet Controls项将Internet对象引用介入到工程中
Private Sub Form_Load()
Dim objIE As Object
For Each objIE In dWinFolder
If InStr(1, objIE.FullName, "IEXPLORE.EXE", vbTextCompare) <> 0 Then
List1.AddItem objIE.LocationURL
End If
Next
Command1.Caption = "正文"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set dWinFolder = Nothing
End Sub
Private Sub List1_Click()
Dim objDoc As Object
Dim objIE As Object
For Each objIE In dWinFolder
If objIE.LocationURL = List1.List(List1.ListIndex) Then
Set objDoc = objIE.Document
For i = 1 To objDoc.All.length - 1
If objDoc.All(i).tagname = "BODY" Then
Text1.Text = objDoc.All(i).innerText
End If
Next
Exit For
End If
Next
End Sub
新建一个工程。加入一个internet transfer contril 一个commandbutton
两个textbox
text1用来输入要取的网页的地址
text2用来输入要存文件的完整文件名
private sub command1_click()
dim b() as byte
inet1.cancel
inet1.protocol=ichttp
inet1.url=text1.text
b()=inet1.openurl(,icbytearray)
open text2.text for binary access write as #1
put #1,,b()
close #1
end sub
看看吧
绝对通过的程序。
先引用Microsoft Internet Controls
再写程序:
Dim dWinFolder As ShellWindows
Private Sub Command1_Click()
dim i as integer
List1.Clear
For i = o To dWinFolder.Count - 1
List1.AddItem dWinFolder.Item(i).LocationURL
Next i
End Sub
Private Sub Form_Load()
Set dWinFolder = New ShellWindows
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set dWinFolder = Nothing
End Sub