用ExtractIcon!
一个例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, FileCtrl,ShellAPI;
type
TForm1 = class(TForm)
Image1: TImage;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
DriveComboBox1: TDriveComboBox;
procedure FileListBox1Click(Sender: TObject);
private
procedure NextIcon;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.NextIcon;
var I:Integer;
FileName:string;
Count:Integer;
begin
// if (FileName<>EditFileName.Text) then
if (FileName<>FileListBox1.FileName) then
begin
FileName:=FileListBox1.FileName;
I:=0;
Count:=ExtractIcon(Application.Handle,PChar(FileName),$FFFFFFFF);
end
else
inc(I);
if (I<Count) then
Image1.Picture.Icon.Handle:=ExtractIcon(Application.Handle,PChar(FileName),I)
else
ShowMessage('No more Images');
end;
procedure TForm1.FileListBox1Click(Sender: TObject);
begin
if FileListBox1.FileName<>'' then
NextIcon;
end;
end.