Einzelnen Beitrag anzeigen

Benutzerbild von wicht
wicht

Registriert seit: 15. Jan 2006
Ort: Das schöne Enger nahe Bielefeld
809 Beiträge
 
Delphi XE Professional
 
#18

Re: Bestimmtes Icon aus Shell32.dll laden

  Alt 13. Nov 2009, 13:34
Mal zuhause eingewählt, das hier habe ich gefunden. Ich benutze ein TListView, um die Icons anzuzeigen, und die sehen eigentlich alle ganz cremig aus. Vielleicht hilft das noch (obwohl es genau so aussieht wie dein Code...), ansonsten bin ich raus...

Delphi-Quellcode:
unit IconManager;

interface

uses
  Windows, SysUtils, Controls, ShellApi, Generics.Collections, Functions;

type
  TIconManager = class
  private
    FDirIndex: Integer;
    FImages: TImageList;
    FData: TDictionary<string, Integer>;
    function FGetIconIndex(Extension: string): Integer;
  public
    constructor Create;
    destructor Destroy; override;
    property DirIndex: Integer read FDirIndex;
    property Images: TImageList read FImages;
    property Icon[Extension: string]: Integer read FGetIconIndex;
  end;

implementation

{ TIconManager }

constructor TIconManager.Create;
var
  SysIL: uint;
  SFI: TSHFileInfoW;
begin
  FData := TDictionary<string, Integer>.Create();
  FImages := TImageList.Create(nil);
  SysIL := SHGetFileInfoW('', 0, SFI, SizeOf(SFI), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SYSICONINDEX);
  if SysIL <> 0 then
  begin
    FImages.Handle := SysIL;
  end;

  SHGetFileInfoW(PChar(GetSystemDir), 0, SFI, SizeOf(TSHFileInfoW), SHGFI_ICON or SHGFI_SMALLICON);
  FDirIndex := SFI.iIcon;
end;

destructor TIconManager.Destroy;
begin
  FImages.Free;
  FData.Free;
  inherited;
end;

function TIconManager.FGetIconIndex(Extension: string): Integer;
var
  SFI: TSHFileInfoW;
begin
  if not FData.ContainsKey(Extension) then
  begin
    SHGetFileInfoW(PChar(Extension), 0, SFI, SizeOf(TSHFileInfoW), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_USEFILEATTRIBUTES);
    FData.Add(Extension, SFI.iIcon);
  end;
  Result := FData[Extension];
end;

end.
http://streamwriter.org

"I make hits. Not the public. I tell the DJ’s what to play. Understand?"
  Mit Zitat antworten Zitat