如何以较简便的方法获取任意文件的图标(50分)

草动

Unregistered / Unconfirmed
GUEST, unregistred user!
是否有较简便的方法获取任意文件的图标?
例如在Listview中显示的文件列表我
想显示出它们的缺省图标.
 
根据扩展名到注册表中查出相应的可执行文件, 找到相应的Exe文件, 用ExtractIcon
API函数得到该文件的图标.
例如: .ZIP -> WinZip -> c:/program files/winzip/winzip32.exe
 
补充一句:还有一个ExtractAssociatedIcon函数

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);

The ExtractAssociatedIcon function first looks for
the indexed icon in the file specified by lpIconPath.
If the function cannot obtain the icon handle from that file,
and the file has an associated executable file,
it looks in that executable file for an icon.
Associations with executable files are based on filename extensions,
are stored in the per-user part of the registry,
and can be defined using File Manager's Associate command.
 
delphi 里有个例子!res...里有类!
 
会长的方法最好

深度历险有个控件
 
多人接受答案了。
 
顶部