unit untShellIcons;
interface
uses
Windows, ShellAPI;
type
TShellIcons = class
private
FLargeImageHandle: integer;
FSmallImageHandle: integer;
FDesktopIndex: integer;
FMyComputerIndex: integer;
FNetworkIndex: integer;
FRecycleBinIndex: integer;
FCloseFolderIndex: integer;
FOpenFolderIndex: integer;
FLinkOverlayIndex: integer;
FShareOverlayIndex: integer;
FFolderTypeName: string;
public
constructor Create;
function GetIconIndex(fn: string): integer;
function GetTypeName(fn: string): string;
property LargeImageHandle: integer read FLargeImageHandle;
property SmallImageHandle: integer read FSmallImageHandle;
property DesktopIndex: integer read FDesktopIndex;
property MyComputerIndex: integer read FMyComputerIndex;
property NetworkIndex: integer read FNetworkIndex;
property RecycleBinIndex: integer read FRecycleBinIndex;
property CloseFolderIndex: integer read FCloseFolderIndex;
property OpenFolderIndex: integer read FOpenFolderIndex;
property LinkOverlayIndex: integer read FLinkOverlayIndex;
property ShareOverlayIndex: integer read FShareOverlayIndex;
property FolderTypeName: string read FFolderTypeName;
end;
var
ShellIcons: TShellIcons;
implementation
uses
ShlObj, SysUtils;
constructor TShellIcons.Create;
var
itemIDs: PItemIDList;
shInfo: TSHFileInfo;
begin
FLargeImageHandle := SHGetFileInfo(
'', 0, shInfo, SizeOf(shInfo), SHGFI_SYSICONINDEX or SHGFI_LARGEICON
);
FSmallImageHandle := SHGetFileInfo(
'', 0, shInfo, SizeOf(shInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON
);
SHGetSpecialFolderLocation(0, CSIDL_DESKTOP, itemIDs);
SHGetFileInfo(
PChar(itemIDs), 0, shInfo, Sizeof(shInfo), SHGFI_PIDL or SHGFI_SYSICONINDEX
);
FDesktopIndex := shInfo.iIcon;
SHGetSpecialFolderLocation(0, CSIDL_DRIVES, itemIDs);
SHGetFileInfo(
PChar(itemIDs), 0, shInfo, Sizeof(shInfo), SHGFI_PIDL or SHGFI_SYSICONINDEX
);
FMyComputerIndex := shInfo.iIcon;
SHGetSpecialFolderLocation(0, CSIDL_NETWORK, itemIDs);
SHGetFileInfo(
PChar(itemIDs), 0, shInfo, Sizeof(shInfo), SHGFI_PIDL or SHGFI_SYSICONINDEX
);
FNetworkIndex := shInfo.iIcon;
SHGetSpecialFolderLocation(0, CSIDL_BITBUCKET, itemIDs);
SHGetFileInfo(
PChar(itemIDs), 0, shInfo, Sizeof(shInfo), SHGFI_PIDL or SHGFI_SYSICONINDEX
);
FRecycleBinIndex := shInfo.iIcon;
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, itemIDs);
SHGetFileInfo(
PChar(itemIDs), 0, shInfo, Sizeof(shInfo), SHGFI_PIDL or SHGFI_SYSICONINDEX
);
FCloseFolderIndex := shInfo.iIcon;
SHGetFileInfo(
PChar(itemIDs), 0, shInfo, Sizeof(shInfo),
SHGFI_PIDL or SHGFI_SYSICONINDEX or SHGFI_OPENICON or SHGFI_TYPENAME
);
FOpenFolderIndex := shInfo.iIcon;
FFolderTypeName := shInfo.szTypeName;
FLinkOverlayIndex := 1;
FShareOverlayIndex := 0;
end;
// get shell icon index from file which may not exists.
function TShellIcons.GetIconIndex(fn: string): integer;
var
shInfo: TSHFileInfo;
begin
SHGetFileInfo(
PChar(fn), FILE_ATTRIBUTE_NORMAL, shInfo, SizeOf(shInfo),
SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES
);
Result := shInfo.iIcon;
end;
// get shell type name from file which may not exists.
function TShellIcons.GetTypeName(fn: string): string;
var
shInfo: TSHFileInfo;
ext: string;
fs: string;
begin
SHGetFileInfo(
PChar(fn), FILE_ATTRIBUTE_NORMAL, shInfo, SizeOf(shInfo),
SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES
);
Result := shInfo.szTypeName;
if Length(Result) = 0 then begin
ext := ExtractFileExt(fn);
if Length(ext) > 0 then ext := ext + ' ';
if (GetUserDefaultLangID and $3ff) = LANG_KOREAN then fs := '¨¡AAI'
else fs := 'File';
Result := ext + fs;
end;
end;
initialization
ShellIcons := TShellIcons.Create;
finalization
ShellIcons.Free;
end. |
|