获取文件关联程序图标 for delphi

unitFileAssociationDetails;{ Created : 2009-05-07 Description : Class to get file type description and icons. * Extensions and Descriptions are held in a TStringLists. * Icons are stored in a TImageList. Assumption is all lists are in same order.}interfaceusesClasses,Controls;typeTFileAssociationDetails=class(TObject)privateFImages:TImageList;FExtensions:TStringList;FDescriptions:TStringList;publicconstructorCreate;destructorDestroy;override;procedureAddFile(FileName:string);procedureAddExtension(Extension:string);procedureClear;procedureGetFileIconsAndDescriptions;propertyImages:TImageListreadFImages;propertyExtensions:TStringListreadFExtensions;propertyDescriptions:TStringListreadFDescriptions;end;implementationusesSysUtils,ShellAPI,Graphics,Windows;{ TFileAssociationDetails }constructorTFileAssociationDetails.Create;begintryinherited;FExtensions:=TStringList.Create;FExtensions.Sorted:=true;FDescriptions:=TStringList.Create;FImages:=TImageList.Create(nil);exceptend;end;destructorTFileAssociationDetails.Destroy;begintryFExtensions.Free;FDescriptions.Free;FImages.Free;finallyinherited;end;end;procedureTFileAssociationDetails.AddFile(FileName:string);beginAddExtension(ExtractFileExt(FileName));end;procedureTFileAssociationDetails.AddExtension(Extension:string);beginExtension:=UpperCase(Extension);if(Trim(Extension)<>'')and(FExtensions.IndexOf(Extension)=-1)thenFExtensions.Add(Extension);end;procedureTFileAssociationDetails.Clear;beginFExtensions.Clear;end;procedureTFileAssociationDetails.GetFileIconsAndDescriptions;varIcon:TIcon;iCount:integer;Extension:string;FileInfo:SHFILEINFO;beginFImages.Clear;FDescriptions.Clear;Icon:=TIcon.Create;try// Loop through all stored extensions and retrieve relevant infoforiCount:=0toFExtensions.Count-1dobeginExtension:='*'+FExtensions.Strings[iCount];// Get description typeSHGetFileInfo(PChar(Extension),FILE_ATTRIBUTE_NORMAL,FileInfo,SizeOf(FileInfo),SHGFI_TYPENAMEorSHGFI_USEFILEATTRIBUTES);FDescriptions.Add(FileInfo.szTypeName);// Get icon and copy into ImageListSHGetFileInfo(PChar(Extension),FILE_ATTRIBUTE_NORMAL,FileInfo,SizeOf(FileInfo),SHGFI_ICONorSHGFI_SMALLICONorSHGFI_SYSICONINDEXorSHGFI_USEFILEATTRIBUTES);Icon.Handle:=FileInfo.hIcon;FImages.AddIcon(Icon);end;finallyIcon.Free;end;end;end.