Author: Jonas Bilinkevicius
In my program, I am displaying a set of path and file names on the screen as the
user choses them using a TList box. Alongside this list box I would like to display
the icon associated with each one (if available). I understand that some icons are
embedded in the executable and others are associated by Windows. Can you point me
in the right direction for determining what the icon is, programmatically
extracting it and placing it into an image array.
Answer:
1 2 procedure TForm1.Button1Click(Sender: TObject);
3 var4 HIcon: THandle;
5 iIcon: Word;
6 FilePath: array[0..MAX_PATH] of Char;
7 begin8 if OpenDialog1.Execute then9 begin10 Label1.Caption := OpenDialog1.FileName;
11 Label1.Repaint;
12 StrPCopy(FilePath, OpenDialog1.FileName);
13 HIcon := ExtractAssociatedIcon(Application.Handle, @FilePath[0], iIcon);
14 if HIcon <> 0 then15 Image1.Picture.Icon.Handle := HIcon;
16 end;
17 end;