• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

判断一个文件是否在IE的缓存中

发布: 2007-7-14 20:28 | 作者: 佚名    | 来源: 网络转载     | 查看: 17次 | 进入软件测试论坛讨论

领测软件测试网 当你建立一个联到网上文件的快捷方式时,你可能需要知道它是否已经被访问过,于是你就可以适当地改变链接的颜色等等。这则小技巧

就是告诉你如何判断一个文件是否在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没找到的原因,它将被显示在随后的的方括号内。

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网