tags:

views:

248

answers:

2

can someone find the folder used which the icons are pulled from> I was wanting to see only the icons and name from C:\Program Files or the registry of HKEY_LOCAL_MACHINE\SOFTWARE but NOT both.

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;

how can I just call icons from the my programs folder, but ONLY the ones I want? for example, i just want to show limewire, norton and say for example winmx. How can I create code to only call those icons that match the ones required in my code? if the name NORTON is in my code it only pulls in norton?

Reply to malach: yes but this needs to work on another computer within my network. I have the code all done, just need to make it to only search for names I want within that place.

I want to search in onlt my programs, and only pull back icons from the files I want, not every folder.

+2  A: 

Icons can be stored in several places. They can be ICO files, or resources attached to the executable or attached to an external DLL (ICL files are really just DLL files that contain nothing but ICO resources).

The SHGetFileInfo routine you are calling is a method of getting an icon that represents the specific file by first looking at the file itself and seeing if it contains an ICO resource, if it does then that is returned...if not then it looks up the file extension via the registry to see if it has an icon attached, if so then that is returned.

skamradt
A: 

You can use

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

to load certain icons.

Yet there is no folder for these icons. You can retrieve them from the executables using a ressource editor, if you want, or search an icon library on the web to provide it for you.

Another way would be to just show only the icons of certain programs or extensions you provide a list for in your program. Something like this:

      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;

The main problem with providing your own icons would be to recognize what icon would belong to what files. No easy solution but knowing.

The icons retrieved in your program by the way can differ from pc to pc, as users can associate different icons with a program. It would maybe be disturbing for the user to see other icons then they are used to associated with files.

Ralph Rickenbach