インターネットのキャッシュを取得 <TOP>
FindFirstUrlCacheEntryインターネットキャッシュの列挙を開始 FindNextUrlCacheEntry インターネットキャッシュの次の項目を検索 FindCloseUrlCache インターネットキャッシュの列挙ハンドルを閉じる MoveMemory メモリの指定領域をコピー lstrlen 指定された文字列のバイトまたは文字の長さを返す lstrcpy 文字列をコピーする
ListBoxに入る項目数が多い場合、表示しながら取得すると時間がかかるので、全て取得するまでダミー(List2)のListBoxを表示させておき全て取得した時点で
List1に切替表示させています。
例では、約6,800項目を表示するのに通常 2秒60、全項目取得後に切り替えると 1秒60 でした。
'================================================================ '= ブラウザのキャッシュを取得 '= (FindFirstUrlCacheEntry.bas) '================================================================ #include "Windows.bi" Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Type INTERNET_CACHE_ENTRY_INFO dwStructSize As Long lpszSourceUrlName As Long lpszLocalFileName As Long CacheEntryType As Long 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 Long dwExemptDelta As Long End Type Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type ' インターネットキャッシュの列挙を開始 Declare Function Api_FindFirstUrlCacheEntry& Lib "wininet" Alias "FindFirstUrlCacheEntryA" (ByVal lpszUrlSeaRethPattern$, ByRef lpFirstCacheEntryInfo As Any, ByRef lpdwFirstCacheEntryInfoBufferSize&) ' インターネットキャッシュの次の項目を検索 Declare Function Api_FindNextUrlCacheEntry& Lib "wininet" Alias "FindNextUrlCacheEntryA" (ByVal hEnumHandle&, ByRef lpNextCacheEntryInfo As Any, ByRef lpdwNextCacheEntryInfoBufferSize&) ' インターネットキャッシュの列挙ハンドルを閉じる Declare Function Api_FindCloseUrlCache& Lib "wininet" Alias "FindCloseUrlCache" (ByVal hEnumHandle&) ' メモリの指定領域をコピー Declare Sub MoveMemory Lib "Kernel32" Alias "RtlMoveMemory" (Dest As Any, Source As Any, ByVal length&) ' 指定された文字列のバイトまたは文字の長さを返す Declare Function Api_lstrlen& Lib "Kernel32" Alias "lstrlenA" (ByVal lpString&) ' 文字列をコピーする Declare Function Api_lstrcpy& Lib "Kernel32" Alias "lstrcpyA" (ByVal lpszString1$, ByVal lpszString2&) #define NORMAL_CACHE_ENTRY &H1 '通常のキャッシュエントリー #define URLHISTORY_CACHE_ENTRY &H200000 'URLキャッシュエントリー #define ERROR_NO_MORE_FILES 18 'これ以上ファイルがない #define ERROR_INSUFFICIENT_BUFFER 122 'システム コールに渡されるデータ領域が小さい Var Shared List1 As Object Var Shared List2 As Object Var Shared Text1 As Object Var Shared Button1 As Object List1.Attach GetDlgItem("List1") : List1.SetFontSize 12 : List1.SetWindowSize 478, 210 List2.Attach GetDlgItem("List2") : List2.SetFontSize 12 : List2.SetWindowSize 478, 210 Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14 Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() ShowWindow -1 List1.ShowWindow -1 End Sub '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var EnumHandle As Long Var icei As INTERNET_CACHE_ENTRY_INFO Var BuffSize As Long Var Ret As Long BuffSize = 0 Ret = Api_FindFirstUrlCacheEntry("", ByVal 0, BuffSize) Dim bICEI(BuffSize) As Byte icei.dwStructSize = Len(icei) MoveMemory bICEI(0), icei, Len(icei) EnumHandle = Api_FindFirstUrlCacheEntry("", bICEI(0), BuffSize) If EnumHandle = 0 Then A% = MessageBox("", "キャッシュを取得できません!", 0, 2) Exit Sub End If MoveMemory icei, bICEI(0), Len(icei) Var SourceUrlName As String Var LocalFileName As String '表示項目が多い場合時間がかかるので全て取得してから表示させている List1.Resetcontent List2.Resetcontent List1.ShowWindow 0 List2.ShowWindow -1 Do If icei.CacheEntryType And NORMAL_CACHE_ENTRY Then SourceUrlName = String$(Api_lstrlen(icei.lpszSourceUrlName), 0) LocalFileName = String$(Api_lstrlen(icei.lpszLocalFileName), 0) Ret = Api_lstrcpy(SourceUrlName, icei.lpszSourceUrlName) Ret = Api_lstrcpy(LocalFileName, icei.lpszLocalFileName) List1.AddString SourceUrlName End If BuffSize = 0 Ret = Api_FindNextUrlCacheEntry(EnumHandle, ByVal 0, BuffSize) If Ret <> 0 Then Exit Do If BuffSize = 0 Then Exit Do Erase bICEI Var bICEI(BuffSize) As Byte icei.dwStructSize = Len(icei) MoveMemory bICEI(0), icei, Len(icei) Ret = Api_FindNextUrlCacheEntry(EnumHandle, bICEI(0), BuffSize) If Ret = 0 Then Exit Do If Ret = ERROR_NO_MORE_FILES Then Exit Do If Ret = ERROR_INSUFFICIENT_BUFFER Then Exit Do MoveMemory icei, bICEI(0), Len(icei) Loop List2.ShowWindow 0 List1.ShowWindow -1 Ret = Api_FindCloseUrlCache(EnumHandle) Text1.SetWindowText Str$(List1.GetCount) & " files listed." End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End