1,453
社区成员




'下载文件
Public 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
'清除缓存
Public Declare Function DeleteUrlCacheEntry Lib "wininet" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Public Function DownloadFile(Url As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, Url, LocalFilename, 0, 0)
If lngRetVal = 0 Then
DownloadFile = True
DeleteUrlCacheEntry Url '清除缓存
End If
End Function
使用方法:
DownloadFile "http://www.baidu.com/img/lm.gif", App.Path & "\lm.gif"
'网络图片地址
Dim FileByte() As Byte '定义一个字节数组
'下载远程数据到字节数组
FileByte = Inet1.OpenURL("http://avatar.profile.csdn.net/9/E/E/2_SupermanKing.jpg", icByteArray)
'将字节数组中的数据保存到硬盘上
Open "C:\MyTemp.TMP" For Binary As #1
Put #1, 1, FileByte
Close #1
'加载硬盘上的文件到 Picture1 对象中
Picture1.Picture = LoadPicture("C:\MyTemp.TMP")
Kill "C:\MyTemp.TMP" '删除临时文件