判斷一個檔案是否在IE的快取中 (轉)
判斷一個檔案是否在IE的快取中 (轉)[@more@] 當你建立一個聯到網上的快捷方式時,你可能需要知道它是否已經被訪問過,於是你就可以適當地改變連結的顏色等等。這則小技巧
就是告訴你如何判斷一個檔案是否在Inte Explorer的快取中,以滿足你的須要。
新建一個專案、新增一個模組。將以下程式碼寫到模組裡:
Private Const ERROR_INSUFFICIENT_BUFFER = 122
Private Const eeErrorBase = 26720
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
lpszUrlName As String
lpszLocalFileName As String
CacheEntryType As String
dwUseCount As Long
dwHitRate As Long
dwSizeLow As Long
dwSizeHigh As Long
LastModifiedTime As FILETIME
ExpireTIme As FILETIME
LastAccessTime As FILETIME
LastSyncTime As FILETIME
lpHeaderInfo As Long
dwHeaderInfoSize As Long
lpszFileExtension As String
dwReserved As Long
End Type
Private Declare Function GetUrlCacheEntryInfo Lib "wininet.dll" _
Alias "GetUrlCacheEntryInfoA" (ByVal sUrlName As String, _
lpCacheEntryInfo As Any, lpdwCacheEntryInfoBufferSize _
As Long) As Long
'用來報告產生的錯誤:
Private Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Private Const FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000
Private Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Private Const FORMAT_MESSAGE_FROM_STRING = &H400
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200
Private Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF
Private Declare Function FormatMessage Lib "kernel32" Alias _
"FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, _
ByVal dwMessageId As Long, ByVal dguageId As Long, _
ByVal lpBuffer As String, ByVal nSize As Long, Arguments _
As Long) As Long
Public Function WinAPIError(ByVal lLastDLLError As Long) As String
Dim sBuff As String
Dim lCount As Long
'返回與LastDLLError相關的出錯資訊:
sBuff = String$(256, 0)
lCount = FormatMessage( _
FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, _
0, lLastDLLError, 0&, sBuff, Len(sBuff), ByVal 0)
If lCount Then
WinAPIError = Left$(sBuff, lCount)
End If
End Function
Public Function GetCacheEntryInfo(ByVal hWnd As Long, _
ByVal lpszUrl As String) As Boolean
Dim dwEntrySize As Long
Dim lpCacheEntry As INTERNET_CACHE_ENTRY_INFO
Dim dwTemp As Long
Dim lErr As Long
If (GetUrlCacheEntryInfo(lpszUrl, ByVal 0&, dwEntrySize)) = 0 Then
lErr = Err.LastDllError
If (lErr <> ERROR_INSUFFICIENT_BUFFER) Then
'預料外的錯誤。須要顯示出錯原因:
Err.Raise eeErrorBase + 1, _
App.EXEName & ".mCacheEntry", WinAPIError(lErr)
GetCacheEntryInfo = False
Exit Function
Else
'這是預料中的錯誤
GetCacheEntryInfo = True
End If
End If
End Function
在窗體上新增一個Command和一個Text。然後加入這些程式碼:
Option Explicit
Private Sub Command1_Click()
On Error Goto ErrorHandler
'檢查Text中的URL地址是否出現在快取中:
If (GetCacheEntryInfo(Me.hWnd, Text1.Text)) Then
MsgBox "URL In Cache.", vbInformation
Else
MsgBox "URL Not In Cache.", vbInformation
End If
Exit Sub
ErrorHandler:
MsgBox "URL Not in Cache [" & Err.Description & "]",vbInformation
End Sub
執行,在Text中鍵入一個URL地址(比如,)當你按下Command按鈕時,就會得到一則訊息報告URL在不在快取中。如果給出了URL沒找到的原因,它將被顯示在隨後的的方括號內。
就是告訴你如何判斷一個檔案是否在Inte Explorer的快取中,以滿足你的須要。
新建一個專案、新增一個模組。將以下程式碼寫到模組裡:
Private Const ERROR_INSUFFICIENT_BUFFER = 122
Private Const eeErrorBase = 26720
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
lpszUrlName As String
lpszLocalFileName As String
CacheEntryType As String
dwUseCount As Long
dwHitRate As Long
dwSizeLow As Long
dwSizeHigh As Long
LastModifiedTime As FILETIME
ExpireTIme As FILETIME
LastAccessTime As FILETIME
LastSyncTime As FILETIME
lpHeaderInfo As Long
dwHeaderInfoSize As Long
lpszFileExtension As String
dwReserved As Long
End Type
Private Declare Function GetUrlCacheEntryInfo Lib "wininet.dll" _
Alias "GetUrlCacheEntryInfoA" (ByVal sUrlName As String, _
lpCacheEntryInfo As Any, lpdwCacheEntryInfoBufferSize _
As Long) As Long
'用來報告產生的錯誤:
Private Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Private Const FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000
Private Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Private Const FORMAT_MESSAGE_FROM_STRING = &H400
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200
Private Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF
Private Declare Function FormatMessage Lib "kernel32" Alias _
"FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, _
ByVal dwMessageId As Long, ByVal dguageId As Long, _
ByVal lpBuffer As String, ByVal nSize As Long, Arguments _
As Long) As Long
Public Function WinAPIError(ByVal lLastDLLError As Long) As String
Dim sBuff As String
Dim lCount As Long
'返回與LastDLLError相關的出錯資訊:
sBuff = String$(256, 0)
lCount = FormatMessage( _
FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, _
0, lLastDLLError, 0&, sBuff, Len(sBuff), ByVal 0)
If lCount Then
WinAPIError = Left$(sBuff, lCount)
End If
End Function
Public Function GetCacheEntryInfo(ByVal hWnd As Long, _
ByVal lpszUrl As String) As Boolean
Dim dwEntrySize As Long
Dim lpCacheEntry As INTERNET_CACHE_ENTRY_INFO
Dim dwTemp As Long
Dim lErr As Long
If (GetUrlCacheEntryInfo(lpszUrl, ByVal 0&, dwEntrySize)) = 0 Then
lErr = Err.LastDllError
If (lErr <> ERROR_INSUFFICIENT_BUFFER) Then
'預料外的錯誤。須要顯示出錯原因:
Err.Raise eeErrorBase + 1, _
App.EXEName & ".mCacheEntry", WinAPIError(lErr)
GetCacheEntryInfo = False
Exit Function
Else
'這是預料中的錯誤
GetCacheEntryInfo = True
End If
End If
End Function
在窗體上新增一個Command和一個Text。然後加入這些程式碼:
Option Explicit
Private Sub Command1_Click()
On Error Goto ErrorHandler
'檢查Text中的URL地址是否出現在快取中:
If (GetCacheEntryInfo(Me.hWnd, Text1.Text)) Then
MsgBox "URL In Cache.", vbInformation
Else
MsgBox "URL Not In Cache.", vbInformation
End If
Exit Sub
ErrorHandler:
MsgBox "URL Not in Cache [" & Err.Description & "]",vbInformation
End Sub
執行,在Text中鍵入一個URL地址(比如,)當你按下Command按鈕時,就會得到一則訊息報告URL在不在快取中。如果給出了URL沒找到的原因,它將被顯示在隨後的的方括號內。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-995722/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Python判斷一個檔案中的字串是否存在於另外一個檔案中Python字串
- PHP 判斷一個字元是否在字串中PHP字元字串
- 判斷一個物件是否為空物件,判斷一個物件中是否有空值物件
- 如何判斷一個物件是否在指定物件的原型鏈中物件原型
- golang判斷檔案是否存在Golang
- vc判斷檔案是否存在
- 在Oracle中,如何判斷一個字串是否為數字?Oracle字串
- 原生js如何判斷一個核取方塊是否選中JS
- 判斷檔案中是否存在中文字元字元
- python 判斷檔案是否存在Python
- Node判斷檔案是否連結
- java判斷檔案是否存在並建立檔案Java
- js如何判斷指定的檔案是否存在JS
- 判斷某一個字串是否存在另一個字串中字串
- js如何判斷一個checkbox核取方塊是否被選中JS
- jQuery如何判斷一個checkbox核取方塊是否被選中jQuery
- 判斷excel檔案是否被開啟Excel
- 如何判斷一個元素是否在可視範圍
- 如何判斷一個元素是否在可視區域中?
- 判斷是否在微信瀏覽器中瀏覽器
- Python Tips 01 : 判斷兩個檔案是否相同Python
- golang中判斷兩個slice是否相等與判斷值下的 陣列是否相等Golang陣列
- PHP判斷檔案是否為圖片的方法PHP
- 程式怎麼判斷一個go原始檔中是否有main函式?GoAI函式
- jquery怎麼樣判斷檔案是否存在jQuery
- C# 判斷遠端檔案是否存在C#
- python判斷檔案是否存在等操作Python
- shell 判斷檔案或路徑是否存在
- C語言判斷檔案是否存在,判斷檔案可讀可寫可執行C語言
- js如何判斷是否是IE瀏覽器JS瀏覽器
- 如何判斷一個元素在億級資料中是否存在?
- Array · 判斷某元素是否在陣列中陣列
- Python 判斷檔案是否存在的三種方法Python
- 判斷一個字串是否包含一個子串的方法字串
- 判斷一個陣列是否排好序陣列
- JS——判斷一個物件是否為空JS物件
- jQuery如何判斷一個元素是否存在jQuery
- 如何判斷一個jquery物件是否存在jQuery物件