这样下载试试'把指定给定一个网络文件(任何类型,可以是图像文件)的地址,然后用程序把其保存为本机器的文件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'保存网上的图片到硬盘 'URL是图版的网址 'LocalFilename 是保存到本地的文件名及目录 '使用例子:DownloadFile "http://www.21cn.com/aa.jpg","c:\aa.jpg"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 End Function
//但是对于不同的系统,我如何正确得到缓存中的文件路径呢Option Explicit Const CSIDL_DESKTOP = &H0 Private Const CSIDL_INTERNET = &H1 Const CSIDL_PROGRAMS = &H2 Const CSIDL_CONTROLS = &H3 Const CSIDL_PRINTERS = &H4 Const CSIDL_PERSONAL = &H5 Const CSIDL_FAVORITES = &H6 Const CSIDL_STARTUP = &H7 Const CSIDL_RECENT = &H8 Const CSIDL_SENDTO = &H9 Const CSIDL_BITBUCKET = &HA Const CSIDL_STARTMENU = &HB Const CSIDL_DESKTOPDIRECTORY = &H10 Const CSIDL_DRIVES = &H11 Const CSIDL_NETWORK = &H12 Const CSIDL_NETHOOD = &H13 Const CSIDL_FONTS = &H14 Const CSIDL_TEMPLATES = &H15 Const NO_ERROR = 0Private Const CSIDL_INTERNET_CACHE = &H20Const MAX_PATH = 260 Private Type SHITEMID cb As Long abID As Byte End Type Private Type ITEMIDLIST mkid As SHITEMID End Type Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hWnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Private Sub Form_Load() Debug.Print "IE Cache path: " + GetSpecialfolder(CSIDL_INTERNET_CACHE) End Sub Private Function GetSpecialfolder(CSIDL As Long) As String Dim r As Long Dim IDL As ITEMIDLIST 'Get the special folder Dim path As String r = SHGetSpecialFolderLocation(100, CSIDL, IDL) If r = NO_ERROR Then 'Create a buffer path = Space$(512) 'Get the path from the IDList r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal path$) 'Remove the unnecessary chr$(0)'s GetSpecialfolder = Left$(path, InStr(path, Chr$(0)) - 1) Exit Function End If GetSpecialfolder = "" End Function
'把指定给定一个网络文件(任何类型,可以是图像文件)的地址,然后用程序把其保存为本机器的文件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'保存网上的图片到硬盘 'URL是图版的网址 'LocalFilename 是保存到本地的文件名及目录 '使用例子:DownloadFile "http://www.21cn.com/aa.jpg","c:\aa.jpg"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 End Function
'URL是图版的网址
'LocalFilename 是保存到本地的文件名及目录
'使用例子:DownloadFile "http://www.21cn.com/aa.jpg","c:\aa.jpg"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
End Function
Const CSIDL_DESKTOP = &H0
Private Const CSIDL_INTERNET = &H1
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15
Const NO_ERROR = 0Private Const CSIDL_INTERNET_CACHE = &H20Const MAX_PATH = 260
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hWnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Sub Form_Load()
Debug.Print "IE Cache path: " + GetSpecialfolder(CSIDL_INTERNET_CACHE)
End Sub
Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long
Dim IDL As ITEMIDLIST
'Get the special folder
Dim path As String
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NO_ERROR Then
'Create a buffer
path = Space$(512)
'Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(path, InStr(path, Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function
'URL是图版的网址
'LocalFilename 是保存到本地的文件名及目录
'使用例子:DownloadFile "http://www.21cn.com/aa.jpg","c:\aa.jpg"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
End Function