这个分真是受之有愧,早上的时候已经可以看到下载了,刚刚又不行了,就是说读取不到哪个apsx文件了,早上可以的,我在IE的缓存里面已经获得了,只要能在缓存里面获得就没2问题了,我把代码贴上来,因为要现实gif,所以需要下载一个控件GraphicEx,在http://www.2ccc.com 楼主可以把你的email留下,我把工程发给你,可以直接看执行效果的,能力所至,惭愧惭愧
pas文件
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, wininet,
StdCtrls, ComCtrls, Buttons, shlobj, ImgList, ShellApi, ExtCtrls,
OleCtrls, SHDocVw, RxGIF;
const
FILEEXT: string = '.gif';
URLLOCATION: string = 'http://61.133.81.98/GM/Main/Login.aspx';
URLHOST: string = 'http://61.133.81.98';
type
TMainForm = class(TForm)
bbtnGetList: TBitBtn;
ListView1: TListView;
ImageList1: TImageList;
StatusBar1: TStatusBar;
Image1: TImage;
WebBrowser1: TWebBrowser;
procedure bbtnGetListClick(Sender: TObject);
procedure WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
procedure WebBrowser1DownloadComplete(Sender: TObject);
procedure ListView1Click(Sender: TObject);
private
{ Private declarations }
IConList: TStringList; // 图标列表
FIECache: string; // IE 缓存路径
bDownLoadFinished: Boolean;
function GetWinDir(Path: Integer): string;
procedure UpdateInfo(AText: string);
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.bbtnGetListClick(Sender: TObject);
var
lpEntryInfo: PInternetCacheEntryInfo;
hCacheDir: LongWord;
dwEntrySize, dwLastError: LongWord;
ID: Integer;
function GetShellImage(AFileName: string): Integer;
var
Icon: TICon;
SHFileInfo: TSHFileInfo;
begin
Result := IConList.IndexOf(ExtractFileExt(AFileName));
if Result <> -1 then Exit;
Icon := TICon.Create;
SHGetFileInfo(Pchar(AFileName), 0, SHFileInfo, Sizeof(SHFileInfo), SHGFI_SMALLICON or SHGFI_ICON or SHGFI_USEFILEATTRIBUTES);
Icon.Handle := SHFileInfo.hIcon;
IConList.AddObject(ExtractFileExt(AFileName), Icon);
ImageList1.AddIcon(Icon);
Result := IConList.Count - 1;
Icon.ReleaseHandle;
end;
procedure AddInfo(lpEntryInfo: PInternetCacheEntryInfo; ID: Integer);
begin
if Pos(FILEEXT, lpEntryInfo.lpszLocalFileName) = 0 then Exit; // 判断文件类型, 如果不是GIF就退出
if Pos(URLHOST, lpEntryInfo.lpszSourceUrlName) = 0 then Exit; // 判断host,如果不是本网站就退出
with ListView1.items do begin
try
BeginUpdate;
with Add do begin
Caption := IntTostr(ID);
ImageIndex := GetShellImage(lpEntryInfo^.lpszLocalFileName);
subitems.Add(lpEntryInfo^.lpszSourceUrlName);
subitems.Add(ExtractFileName(lpEntryInfo^.lpszLocalFileName));
subitems.Add(lpEntryInfo^.lpszLocalFileName);
end;
UpdateInfo('找到 ' + IntTostr(ListView1.items.Count) + ' 个文件');
finally
EndUpdate;
end;
end;
end;
begin
ID := 0;
ListView1.items.clear;
dwEntrySize := 0;
FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);
GetMem(lpEntryInfo, dwEntrySize);
hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
if hCacheDir <> 0 then
AddInfo(lpEntryInfo, ID);
Inc(ID);
FreeMem(lpEntryInfo);
repeat
dwEntrySize := 0;
FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize);
dwLastError := GetLastError();
if dwLastError = ERROR_INSUFFICIENT_BUFFER then begin
GetMem(lpEntryInfo, dwEntrySize);
if FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize) then begin
AddInfo(lpEntryInfo, ID);
Inc(ID);
end;
FreeMem(lpEntryInfo);
end;
application.ProcessMessages;
until (dwLastError = ERROR_NO_MORE_ITEMS);
ListView1.SetFocus;
ListView1.SelectAll;
end;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited;
FIECache := GetWinDir(CSIDL_INTERNET_CACHE);
IConList := TStringList.Create;
WebBrowser1.Navigate(URLLOCATION);
end;
function TMainForm.GetWinDir(Path: Integer): string;
var
Pid: PItemIDList;
sPath: array[0..255] of char;
begin
try
SHGetSpecialFolderLocation(application.Handle, Path, Pid);
if SHGetPathFromIDList(Pid, sPath) then
{如果文件夹不是系统的一部分就返回False}
Result := StrPas(sPath);
except
UpdateInfo('定位路径有误, 请再试!');
end;
end;
destructor TMainForm.Destroy;
var
I: Integer;
begin
for I := IConList.Count - 1 downto 0 do
TICon(IConList.Objects).Free;
IConList.Free;
inherited;
end;
procedure TMainForm.UpdateInfo(AText: string);
begin
StatusBar1.SimpleText := AText;
end;
procedure TMainForm.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
bDownLoadFinished := False;
bbtnGetList.Enabled := bDownLoadFinished;
end;
procedure TMainForm.WebBrowser1DownloadComplete(Sender: TObject);
begin
bDownLoadFinished := True;
bbtnGetList.Enabled := bDownLoadFinished;
end;
procedure TMainForm.ListView1Click(Sender: TObject);
var
Item : TListItem;
begin
Item := ListView1.Selected;
if not Assigned(item) then exit;
if Pos(FILEEXT, Item.SubItems.Strings[1])> 0 then begin
Image1.Picture.LoadFromFile(Item.SubItems.Strings[2]);// 点击ListView的项目,如果是Gif图片,就会显示在Image框里面
end;
end;
end.
-------------窗体文件
object MainForm: TMainForm
Left = 192
Top = 107
Width = 602
Height = 429
BorderIcons = [biSystemMenu, biMinimize]
Caption = '读取IE临时文件示例'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
PixelsPerInch = 96
TextHeight = 12
object Image1: TImage
Left = 420
Top = 192
Width = 169
Height = 153
end
object bbtnGetList: TBitBtn
Left = 517
Top = 352
Width = 75
Height = 25
Caption = '获取列表'
TabOrder = 0
OnClick = bbtnGetListClick
end
object ListView1: TListView
Left = 4
Top = 192
Width = 405
Height = 181
Columns = <
item
Caption = '序号'
end
item
Alignment = taCenter
Caption = 'Internet地址'
Width = 250
end
item
Caption = '真实文件名'
Width = 100
end
item
Caption = '真实路径'
Width = 0
end>
MultiSelect = True
ReadOnly = True
RowSelect = True
SmallImages = ImageList1
TabOrder = 1
ViewStyle = vsReport
OnClick = ListView1Click
end
object StatusBar1: TStatusBar
Left = 0
Top = 380
Width = 594
Height = 22
Panels = <>
SimplePanel = False
end
object WebBrowser1: TWebBrowser
Left = 8
Top = 8
Width = 581
Height = 169
TabOrder = 3
OnDownloadComplete = WebBrowser1DownloadComplete
OnBeforeNavigate2 = WebBrowser1BeforeNavigate2
ControlData = {
4C0000000C3C0000771100000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
object ImageList1: TImageList
Left = 560
Top = 312
end
end