判斷一個文件是否在IE的緩存中

發表于:2007-07-14來源:作者:點擊數: 標簽:
當你建立一個聯到網上文件的快捷方式時,你可能需要知道它是否已經被訪問過,于是你就可以適當地改變鏈接的顏色等等。這則小技巧 就是告訴你如何判斷一個文件是否在inte .net explorer的緩存中,以滿足你的須要。 新建一個項目、添加一個模塊。將以下代碼寫
當你建立一個聯到網上文件的快捷方式時,你可能需要知道它是否已經被訪問過,于是你就可以適當地改變鏈接的顏色等等。這則小技巧

就是告訴你如何判斷一個文件是否在inte.net 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

  lpszsourceurlname 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


’用來報告api產生的錯誤:

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 dwlanguageid 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地址(比如,http://www.vbaccelerator.com/index.html)當你按下command按鈕時,就會得到一則消息報告url在不在緩存中。如果windows給出了url沒找到的原因,它將被顯示在隨后的的方括號內。

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97