WEBBROWSER控件怎样设置为不加载图片?

2024-12-25 18:24:22
推荐回答(1个)
回答1:

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Sub Command1_Click()
Dim F As String, nURL As String, S As Long
nURL = "http://www.baidu.com/"
F = "C:\baidu.htm"
S = URLDownloadToFile(0, nURL, F, 0, 0) '下载网页源文件,返回 0 表示成功
End Sub

补充:------------------------------
'控件: Command1、text1
'在属性窗口设置 text1 属性:MultiLine = True ScrollBars = 2
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Sub Command1_Click()
Dim F As String, nURL As String, S As Long, nStr As String
nURL = "http://www.baidu.com/"
F = "C:\baidu.htm"
S = URLDownloadToFile(0, nURL, F, 0, 0) '下载网页源文件,返回 0 表示成功
If ReadSaveF(nStr, F) Then Text1.Text = nStr
End Sub

Private Function ReadSaveF(nStr As String, F As String, Optional IsSave As Boolean) As Boolean
'读写文件,IsSave=True 为写,否则为读
Dim H As Long, B() As Byte, S As String

H = FreeFile
On Error GoTo Exit1
If IsSave Then '将变量 nStr 保存到文件
If Dir(F, 7) <> "" Then SetAttr F, 0: Kill F '删除原来的文件
Open F For Binary As #H '用二进制方式打开一个文件
Put #H, , nStr
Close #H
Else '将文件内容读入变量 nStr
S = FileLen(F)
ReDim B(1 To S)
Open F For Binary As #H '用二进制方式打开一个文件
Get #H, , B
Close #H
nStr = StrConv(B, vbUnicode) '字符串转变为 vbUnicode 字符
End If

ReadSaveF = True
Exit Function
Exit1:
Close #H
End Function