uses SHDocVw, WinINet, MsHtml;
//获取IE缓存验证码的图片
Function TFrmMain.GetLocalImg(Bitmap: TBitmap): boolean;
Var
lpEntryInfo: PInternetCacheEntryInfo;
dwEntrySize, dwLastError, Hwd: LongWORD;
Begin
result := false;
IsStop := true;
dwEntrySize := 0;
FindFirstUrlCacheEntry(Nil, TInternetCacheEntryInfo(Nil^), dwEntrySize);
GetMem(lpEntryInfo, dwEntrySize);
Hwd := FindFirstUrlCacheEntry(Nil, lpEntryInfo^, dwEntrySize);
If Hwd <> 0 Then
Begin
Repeat
dwEntrySize := 0;
FindNextUrlCacheEntry(Hwd, TInternetCacheEntryInfo(Nil^), dwEntrySize);
dwLastError := GetLastError();
If dwLastError = ERROR_INSUFFICIENT_BUFFER Then
Begin
GetMem(lpEntryInfo, dwEntrySize);
If FindNextUrlCacheEntry(Hwd, lpEntryInfo^, dwEntrySize) Then
Begin
If Pos(UpperCase('qq.com/getimage?'), UpperCase(lpEntryInfo.lpszSourceUrlName)) > 0 Then
If (FileExists(lpEntryInfo.lpszLocalFileName)){ And (UpperCase(ExtractFileExt(lpEntryInfo.lpszLocalFileName)) = '.BMP')} Then
Begin
Bitmap.FreeImage; //加载验证码BMP图片
Bitmap.LoadFromFile(lpEntryInfo.lpszLocalFileName);
result := true;
End;
If Pos(UpperCase('qq.com'), UpperCase(lpEntryInfo.lpszSourceUrlName)) > 0 Then
DeleteUrlCacheEntry(lpEntryInfo.lpszSourceUrlName); //删除所有属于QQ的缓存网页
End;
End;
Application.ProcessMessages;
Until (dwLastError = ERROR_NO_MORE_ITEMS);
End;
FreeMem(lpEntryInfo);
FindCloseUrlCache(Hwd);
IsStop := false;
End;
//demo
WebBrowser1.Navigate('http://freeqq2.qq.com/2.shtml');
While WebBrowser1.ReadyState <> READYSTATE_COMPLETE Do Application.ProcessMessages;
GetLocalImg(Image1.Picture.Bitmap);
//=============================================================
//另一种方式直接取本地IE缓存文件
Function GetUrlCacheLocalFileName(UrlName: String; Var LocalFName: String): boolean;
Var
lpCacheEntryInfo: PInternetCacheEntryInfo;
DSize: Cardinal;
Begin
result := false;
DSize := 0;
GetUrlCacheEntryInfo(PChar(UrlName), lpCacheEntryInfo^, DSize);
GetMem(lpCacheEntryInfo, DSize);
Try
If GetUrlCacheEntryInfo(PChar(UrlName), lpCacheEntryInfo^, DSize) Then
Begin
LocalFName := lpCacheEntryInfo.lpszLocalFileName;
result := true;
End;
Finally
FreeMem(lpCacheEntryInfo, DSize);
End;
End;
//demo
var Lf:string;
Begin
if GetUrlCacheLocalFileName('http://verify.qq.com/getimage?0.002926716948551733',Lf) then
Image1.Picture.Bitmap.LoadFromFile(Lf);
End;