Internet技巧兩則
兩項互聯網技能
1、判斷某個連接是否存儲在緩存中
使用微軟IE上網時,IE會將你瀏覽過的網頁保存在緩存中,以便你離線瀏覽。
下麪的程序可以確定URL是否在瀏覽器的緩存中。
首先新建一個VB項目文件,在Form1中添加一個CommandButton控件和一個TextBox控件,然後
在Form1的代碼窗口中添加以下代碼:
選項顯式
Private Const ERROR _ INSUFFICIENT _ BUFFER = 122
Private Const ee ERROR base = 26720
私有類型FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
私有類型INTERNET _ CACHE _ ENTRY _ INFO
dwStructSize As Long
lpszsourceurl name As String
lpszLocalFileName As String
CacheEntryType As String
dwuse count As Long
dwsize low As Long
dwsize high As Long
last modified time As FILETIME
ExpireTIme As FILETIME
last access time As FILETIME
私有聲明函數GetUrlCacheEntryInfo Lib" wininet . dll" Alias _
" GetUrlCacheEntryInfoA" _
(ByVal sUrlName爲String,_
lpCacheEntryInfo爲Any,_
lpdwCacheEntryInfoBufferSize爲Long _
)爲Long
Private Const FORMAT _ MESSAGE _ ALLOCATE _ BUFFER = & H100
Private Const FORMAT _ MESSAGE _ ARGUMENT _ ARRAY = & h 2000
Private Const FORMAT _ MESSAGE _ FROM _ HMODULE = & H800
Private Const FORMAT _ MESSAGE _ FROM _ STRING = & H400
Private Const FORMAT _ MESSAGE _ FROM _ SYSTEM = & h 1000
Private Const FORMAT _ MESSAGE _ IGNORE _ INSERTS = & h 200
Private
private Declare Function format message Lib" kernel 32" Alias" format message a" _
(ByVal dw flags爲Long,lpSource爲Any,ByVal dwMessageId爲Long,_
ByVal dwLanguageId爲Long,ByVal lpBuffer爲String,ByVal nSize爲_
Long,Arguments爲Long)Long
公共函數winapi error(ByVal lLastDLLError As String
Dim sBuff As String
Dim lCount As Long
&急性;獲取錯誤消息
sbuff = string $ (256,0)
lCount = format message(_
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函數
公共函數GetCacheEntryInfo(ByVal hWnd爲Long,ByVal lpszUrl爲String)爲Boolean
Dim dwEntrySize爲Long
Dim lpCacheEntry爲INTERNET _ CACHE _ ENTRY _ INFO
Dim dw temp爲Long
Dim lErr爲Long
如果(GetUrlCacheEntryInfo(lpszul,ByVal 0 & amp,dwEntrySize)) = 0,則
lErr = Err。LastDllError
If(lErr ERROR _ INSUFFICIENT _ BUFFER)Then
& acute;該URL不在緩存中
err.raise eeerrorbase 1,app.exename &”。mcacheentry",winapi error(lerr)
getcacheentryinfo = false
exit function
else
& acu URL保存在緩存中
getcacheentryinfo = true
end if
end if
end function
private Sub command 1 _ Click()
On Error GoTo Error handler
If(GetCacheEntryInfo(me . hwnd,1。text)),然後
msgbox"URL保存在緩存中。,VB information
else
msgbox" URL未保存在緩存中。,vbInformation
End If
出口接頭
ErrorHandler:
MsgBox"URL未保存在緩存中["& err.description &"]",VB information
end sub
private form _ load()
form 1 . currentx = 150:form 1 . currenty = 60
form 1 . print"在Text1中輸入URL竝按Command1檢測"
text 1 . text =""
command 1。
運行程序,在文本框中輸入URL地址(例如,http://member.netease.com/~blackcat),然後單擊Command1按鈕。如果URL在緩存中,程序將彈出一個消息框,顯示URL保存在緩存中。
0條評論