【问题标题】:What folder are icons stored in for delphi?delphi的图标存储在哪个文件夹中?
【发布时间】:2009-07-23 22:26:33
【问题描述】:

谁能找到提取图标的文件夹> 我只想查看 C:\Program Files 或 HKEY_LOCAL_MACHINE\SOFTWARE 注册表中的图标和名称,但不能同时查看两者。

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;

我怎样才能从我的程序文件夹中调用图标,但只调用我想要的那些?例如,我只想展示limewire、norton,例如winmx。如何创建代码以仅调用与代码中所需图标匹配的图标?如果 NORTON 这个名字在我的代码中,它只会拉入 Norton?

回复 malach:是的,但这需要在我网络中的另一台计算机上运行。我已经完成了所有代码,只需要让它在那个地方只搜索我想要的名字。

我只想在我的程序中搜索,并且只从我想要的文件中提取图标,而不是每个文件夹。

【问题讨论】:

  • 亲爱的 OP。您似乎回到了这个问题并使用答案添加到它。这不是本网站的工作方式。如果您想添加到问题中,您必须拥有拥有该问题的“jamesmisser”帐户才能对其进行编辑。或者您必须在一个帐户上累积 15 个代表才能对问题或相应答案发表评论。这不是论坛,您不要使用答案进行回复。我留下 tgis 评论希望你能回来。我已将您添加的所有内容添加到原始问题中,并删除了您的答案。

标签: delphi


【解决方案1】:

图标可以存储在多个位置。它们可以是 ICO 文件,也可以是附加到可执行文件或附加到外部 DLL 的资源(ICL 文件实际上只是 DLL 文件,只包含 ICO 资源)。

您正在调用的 SHGetFileInfo 例程是一种获取表示特定文件的图标的方法,方法是首先查看文件本身并查看它是否包含 ICO 资源,如果包含则返回...如果没有则它通过注册表查找文件扩展名以查看是否附加了图标,如果有,则返回。

【讨论】:

    【解决方案2】:

    你可以使用

    Image.Picture.LoadFromFile('norton.ico');
    

    加载某些图标。

    但这些图标没有文件夹。如果需要,您可以使用资源编辑器从可执行文件中检索它们,或者在网络上搜索图标库以提供给您。

    另一种方法是仅显示您在程序中提供列表的某些程序或扩展程序的图标。像这样的:

          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;
    

    提供您自己的图标的主要问题是识别什么图标属于什么文件。没有简单的解决方案,但知道。

    顺便说一句,在您的程序中检索到的图标可能因电脑而异,因为用户可以将不同的图标与程序相关联。用户看到其他图标可能会感到不安,然后他们习惯于与文件关联。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      相关资源
      最近更新 更多