ExtractAssIcon and
paint into Timage?
From: "Joe C. Hecht (Borland)"
<jhecht@corp.borland.com>
> How
can I extract the associated icon (ExtractAssociatedIcon) and draw it into
> a
Timage or a small area of the form?
uses
ShellApi;
procedure
TForm1.Button1Click(Sender: TObject);
var
IconIndex : word;
h : hIcon;
begin
IconIndex := 0;
h :=
ExtractAssociatedIcon(hInstance,
'C:\WINDOWS\NOTEPAD.EXE',
IconINdex);
DrawIcon(Form1.Canvas.Handle,
10,
10,
h);
Inna
Extract
Icon from file
Use
ExtractAssociatedIcon for getting Handle of the icon. And use this result for
Draw method of Canvas.
procedure
TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
end;
procedure
TForm1.Button2Click(Sender: TObject);
var
MyIcon: TIcon;
Filter: Word;
begin
Filter:=0;
MyIcon:=TIcon.Create;
MyIcon.Handle:=ExtractAssociatedIcon(
hInstance,
PChar(Edit1.Text),
Filter);
Image1.Canvas.Draw(0, 0, MyIcon);
end;