利用了 shellapi 中的 TShFileInfo 以及 ShGetFileInfo 来分别取得程序的大小图标
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses shellapi;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
shFileInfo:TShFileInfo;
icon:Ticon;
begin
icon := ticon.Create;
try
if opendialog1.Execute then
begin
shGetFileInfo(pchar(opendialog1.FileName),0,shFileInfo,sizeof(TShFileInfo),
shellapi.SHGFI_ICON or shellapi.SHGFI_LARGEICON or shellapi.SHGFI_TYPENAME
or SHGFI_DISPLAYNAME );
icon.Handle := shFileInfo.hIcon;
self.Image1.Picture.Assign(icon);
form1.Caption:=shFileInfo.szDisplayName;
edit1.Text:=shFileinfo.szTypeName;
self.Image1.Update;
end;
finally
icon.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
shFileInfo:TShFileInfo;
icon:Ticon;
begin
icon := ticon.Create;
try
if opendialog1.Execute then
begin
shGetFileInfo(pchar(opendialog1.FileName),0,shFileInfo,sizeof(TShFileInfo),
shellapi.SHGFI_ICON or shellapi.SHGFI_SMALLICON or shellapi.SHGFI_TYPENAME);
icon.Handle := shFileInfo.hIcon;
self.Image1.Picture.Assign(icon);
self.Image1.Update;
end;
finally
icon.Free;
end;
end;
end.