delphi的图标存储在哪个文件夹中?
有人能找到从中提取图标的文件夹吗> 我只想看到C:\Program Files或HKEY_LOCAL_MACHINE\软件注册表中的图标和名称,但不想同时看到两者delphi的图标存储在哪个文件夹中?,delphi,Delphi,有人能找到从中提取图标的文件夹吗> 我只想看到C:\Program Files或HKEY_LOCAL_MACHINE\软件注册表中的图标和名称,但不想同时看到两者 uses ShellApi; procedure LV_InsertFiles(strPath: string; ListView: TListView; ImageList: TImageList); var i: Integer; Icon: TIcon; SearchRec: TSearchRec; Lis
uses
ShellApi;
procedure LV_InsertFiles(strPath: string; ListView: TListView; ImageList: TImageList);
var
i: Integer;
Icon: TIcon;
SearchRec: TSearchRec;
ListItem: TListItem;
FileInfo: SHFILEINFO;
begin
// Create a temporary TIcon
Icon := TIcon.Create;
ListView.Items.BeginUpdate;
try
// search for the first file
i := FindFirst(strPath + '*.*', faAnyFile, SearchRec);
while i = 0 do
begin
with ListView do
begin
// On directories and volumes
if ((SearchRec.Attr and FaDirectory <> FaDirectory) and
(SearchRec.Attr and FaVolumeId <> FaVolumeID)) then
begin
ListItem := ListView.Items.Add;
//Get The DisplayName
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_DISPLAYNAME);
Listitem.Caption := FileInfo.szDisplayName;
// Get The TypeName
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_TYPENAME);
ListItem.SubItems.Add(FileInfo.szTypeName);
//Get The Icon That Represents The File
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_ICON or SHGFI_SMALLICON);
icon.Handle := FileInfo.hIcon;
ListItem.ImageIndex := ImageList.AddIcon(Icon);
// Destroy the Icon
DestroyIcon(FileInfo.hIcon);
end;
end;
i := FindNext(SearchRec);
end;
finally
Icon.Free;
ListView.Items.EndUpdate;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Assign a Imagelist to the ListView
ListView1.SmallImages := ImageList1;
// Show Listview in Report Style and add 2 Columns
ListView1.ViewStyle := vsReport;
ListView1.Columns.Add;
ListView1.Columns.Add;
LV_InsertFiles('C:\Windows\', ListView1, ImageList1);
end;
使用
贝拉皮;
过程LV_InsertFiles(strPath:string;ListView:TListView;ImageList:TImageList);
变量
i:整数;
图标:提康;
SearchRec:TSearchRec;
列表项:TListItem;
FileInfo:SHFILEINFO;
开始
//创建一个临时TIcon
图标:=TIcon.Create;
ListView.Items.BeginUpdate;
尝试
//搜索第一个文件
i:=FindFirst(strPath+'*.*',faAnyFile,SearchRec);
当i=0时
开始
用ListView做什么
开始
//关于目录和卷
如果((SearchRec.Attr和FaDirectory FaDirectory)和
(SearchRec.Attr和FaVolumeId FaVolumeId))然后
开始
ListItem:=ListView.Items.Add;
//获取显示名
SHGetFileInfo(PChar(strPath+SearchRec.Name),0,FileInfo,
SizeOf(FileInfo),SHGFI\u显示名称);
Listitem.Caption:=FileInfo.szDisplayName;
//获取类型名
SHGetFileInfo(PChar(strPath+SearchRec.Name),0,FileInfo,
SizeOf(文件信息),SHGFI_类型名称);
ListItem.SubItems.Add(FileInfo.szTypeName);
//获取表示文件的图标
SHGetFileInfo(PChar(strPath+SearchRec.Name),0,FileInfo,
SizeOf(FileInfo)、SHGFI_图标或SHGFI_小图标);
icon.Handle:=FileInfo.hIcon;
ListItem.ImageIndex:=ImageList.AddIcon(图标);
//摧毁图标
销毁图标(FileInfo.hIcon);
结束;
结束;
i:=FindNext(SearchRec);
结束;
最后
图标。免费;
ListView.Items.EndUpdate;
结束;
结束;
程序TForm1.按钮1单击(发送方:TObject);
开始
//将Imagelist分配给ListView
ListView1.SmallImages:=ImageList1;
//以报告样式显示Listview并添加2列
ListView1.ViewStyle:=vsReport;
ListView1.Columns.Add;
ListView1.Columns.Add;
LV_插入文件('C:\Windows\',ListView1,ImageList1);
结束;
我如何从“我的程序”文件夹中调用图标,但只调用我想要的图标?例如,我只想展示limewire、norton和winmx。我如何创建代码来只调用那些与代码中所需图标匹配的图标?如果我的代码里有诺顿这个名字,它只会把诺顿拉进来
回复malach:是的,但这需要在我网络中的另一台计算机上工作。我已经完成了所有的代码,只需要让它只在那个地方搜索我想要的名字
我想在线搜索我的程序,只从我想要的文件中提取图标,而不是每个文件夹。图标可以存储在多个地方。它们可以是ICO文件,也可以是附加到可执行文件或附加到外部DLL的资源(ICL文件实际上只是只包含ICO资源的DLL文件)
您正在调用的SHGetFileInfo例程是一种获取表示特定文件的图标的方法,方法是首先查看文件本身并查看其是否包含ICO资源,如果包含ICO资源,则返回该资源…如果不包含,则通过注册表查找文件扩展名以查看是否附加了图标,如果是,则返回。图标可以存储在多个位置。它们可以是ICO文件,也可以是附加到可执行文件或附加到外部DLL的资源(ICL文件实际上只是只包含ICO资源的DLL文件) 您正在调用的SHGetFileInfo例程是一种获取表示特定文件的图标的方法,方法是首先查看文件本身并查看其是否包含ICO资源,如果包含ICO资源,则返回该资源…如果不包含,则通过注册表查找文件扩展名以查看是否附加了图标,如果是,则返回。您可以使用
Image.Picture.LoadFromFile('norton.ico');
加载某些图标
然而,这些图标没有文件夹。如果需要,您可以使用ressource编辑器从可执行文件中检索它们,或者搜索web上的图标库以提供给您
另一种方法是只显示您在程序中为其提供列表的某些程序或扩展的图标。大概是这样的:
ListItem := ListView.Items.Add;
//Get The DisplayName
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_DISPLAYNAME);
// StringListOfIncludedFiles includes all file names you want to show icon for
// find returns true if it found an entry
if StringListOfIncludedFiles.Find(FileInfo.szDisplayName, indexFound) then
Listitem.Caption := FileInfo.szDisplayName;
提供自己的图标的主要问题是识别哪些图标属于哪些文件。没有简单的解决办法,但知道
顺便说一下,在您的程序中检索到的图标可能会因pc而异,因为用户可以将不同的图标与程序关联。如果用户看到与文件关联的其他图标,可能会感到不安。您可以使用
Image.Picture.LoadFromFile('norton.ico');
加载某些图标
然而,这些图标没有文件夹。如果需要,您可以使用ressource编辑器从可执行文件中检索它们,或者搜索web上的图标库以提供给您
另一种方法是只显示您在程序中为其提供列表的某些程序或扩展的图标。大概是这样的:
ListItem := ListView.Items.Add;
//Get The DisplayName
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_DISPLAYNAME);
// StringListOfIncludedFiles includes all file names you want to show icon for
// find returns true if it found an entry
if StringListOfIncludedFiles.Find(FileInfo.szDisplayName, indexFound) then
Listitem.Caption := FileInfo.szDisplayName;
提供自己的图标的主要问题是识别哪些图标属于哪些文件。没有简单的解决办法,但知道
顺便说一下,在您的程序中检索到的图标可能会因pc而异,因为用户可以将不同的图标与程序关联。如果用户看到与文件关联的其他图标,可能会感到不安。亲爱的OP。您似乎返回到这个问题,并使用答案添加到其中。这不是这个网站的工作方式。如果你想添加到问题中,你必须拥有一个拥有该问题的帐户“jamesmisser”来编辑它。或者,您必须在一个帐户上累积15个代表,才能对问题或相应的答案发表评论。这不是一个论坛,你不回答使用答案。我留下tgis评论,希望你能回来。我已将您添加的所有内容添加到原始问题,并删除了您的答案。De