//参考
http://kingron.myetang.com/zsfunc0c.htmuses
ShellApi;function GetSystemImageList(mImageList: TImageList): Boolean;
{ 返回系统图标到图形列表中是否成功 }
var
vHandle: THandle;
vSHFileInfo: TSHFileInfo;
begin
FillChar(vSHFileInfo, SizeOf(vSHFileInfo), 0);
vHandle := SHGetFileInfo('', 0, vSHFileInfo, SizeOf(vSHFileInfo),
SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
Result := vHandle <> 0;
mImageList.Handle := vHandle;
mImageList.ShareImages := True;
end; { GetSystemImageList }
http://kingron.myetang.com/zsfunc0c.htmuses
ShellApi;function GetSystemImageList(mImageList: TImageList): Boolean;
{ 返回系统图标到图形列表中是否成功 }
var
vHandle: THandle;
vSHFileInfo: TSHFileInfo;
begin
FillChar(vSHFileInfo, SizeOf(vSHFileInfo), 0);
vHandle := SHGetFileInfo('', 0, vSHFileInfo, SizeOf(vSHFileInfo),
SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
Result := vHandle <> 0;
mImageList.Handle := vHandle;
mImageList.ShareImages := True;
end; { GetSystemImageList }
如果我只是需要在ListView中显示文件,
它的图标为该文件类型的图标,但是该文件不一定存在,
怎么提取?
也就是说根据文件后缀名提取图标了。
比如:
with TMemoryStream.Create do
begin
SaveToFile('c:\temp.扩展名');
Free;
end;
然后提取图标
结帐意见:taxi得99分,伴水得1分。
begin
Result := Copy(mStr, 1, Pos(mDelimiter, mStr) - 1);
end; { StrLeft }function ListValue(mList: string; mIndex: Integer; mDelimiter: string = ','): string;
var
I, L, K: Integer;
begin
L := Length(mList);
I := Pos(mDelimiter, mList);
K := 0;
Result := '';
while (I > 0) and (K <> mIndex) do begin
mList := Copy(mList, I + Length(mDelimiter), L);
I := Pos(mDelimiter, mList);
Inc(K);
end;
if K = mIndex then Result := StrLeft(mList + mDelimiter, mDelimiter);
end; { ListValue }function SysPath: string;
var
vBuffer: array[0..MAX_PATH] of Char;
begin
GetSystemDirectory(vBuffer, MAX_PATH);
Result := IncludeTrailingPathDelimiter(vBuffer);
end; { SysPath }function ZsFileIcon(mFileName: TFileName): HICON; { 返回文件的图标 }
var
vRegistry: TRegistry;
vExtension, vIconFileName: TFileName;
vIconIndex: Integer;
vExtDescription: string;
begin
// Result := 0;
// if not FileExists(mFileName) then Exit; vRegistry := TRegistry.Create;
try
vExtension := UpperCase(ExtractFileExt(mFilename));
if (vExtension = '.EXE') or (vExtension = '.ICO') then begin
vIconFileName := mFilename;
vIconIndex := 0;
end else begin
vRegistry.RootKey := HKEY_CLASSES_ROOT;
if vRegistry.OpenKey(vExtension, False) then begin
vExtDescription := vRegistry.ReadString('');
vRegistry.OpenKey('\' + vExtDescription, False);
vRegistry.OpenKey('DefaultIcon', False);
vIconFileName := vRegistry.ReadString('');
vIconIndex := StrToIntDef(ListValue(vIconFileName, 1, ','), 0);
vIconFileName := ListValue(vIconFileName, 0, ',');
end else begin
vIconFileName := SysPath + 'Shell32.dll';
vIconIndex := 0;
end;
end;
Result := ExtractIcon(HInstance, PChar(vIconFileName), UINT(vIconIndex));
finally
vRegistry.Free;
end;
end; { ZsFileIcon }procedure TForm1.Button1Click(Sender: TObject);
begin
Icon.Handle := ZsFileIcon(Edit1.Text);
end;(复制完之后,随便把 游少爷 也关在箱子中)