获取外壳图标的最快方法
我使用此代码来获取 shell 图标(Windows 资源管理器中显示的图标)。
有谁有过以更快的方式获取这些图标的经验吗? SHGetFileInfo
似乎相当慢。
procedure TForm2.Button1Click(Sender: TObject);
var
FileInfo: TSHFileInfo;
begin
FillChar(FileInfo, SizeOf(FileInfo), 0);
if SHGetFileInfo(PChar('c:\windows\'), 0, FileInfo, SizeOf(FileInfo),
SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SYSICONINDEX) <> 0 then
DrawIconEx(Canvas.Handle, 10, 10, FileInfo.hIcon, 0, 16, 16, 0, DI_IMAGE or
DI_MASK);
end;
谢谢!
I'm using this code for getting the shell icon (the one displayed in Windows Explorer).
Does anyone has an experience with a faster way to get these icons ? The SHGetFileInfo
seems to be quite slow.
procedure TForm2.Button1Click(Sender: TObject);
var
FileInfo: TSHFileInfo;
begin
FillChar(FileInfo, SizeOf(FileInfo), 0);
if SHGetFileInfo(PChar('c:\windows\'), 0, FileInfo, SizeOf(FileInfo),
SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SYSICONINDEX) <> 0 then
DrawIconEx(Canvas.Handle, 10, 10, FileInfo.hIcon, 0, 16, 16, 0, DI_IMAGE or
DI_MASK);
end;
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也尝试使用 SHGFI_USEFILEATTRIBUTES 标志。请参阅文章
调整 SHGetFileInfo 以获得最佳性能
和SHGFI_USEFILEATTRIBUTES 的作用是什么是什么意思?
了解更多信息。Try using the SHGFI_USEFILEATTRIBUTES flag as well. See the articles
Tuning SHGetFileInfo for Optimum Performance
andWhat does SHGFI_USEFILEATTRIBUTES mean?
for more information.我在使用SHGetFileInfo的时候就已经使用了缓存。除非它是 .exe 或 .ico 文件(也许还有更多),否则相同文件扩展名的图标将是相同的,因此当您显示目录列表时,您可以对相同类型的文件使用相同的图标,并且您不必再次调用(并等待)SHGetFileInfo。
I have used a cache when I used SHGetFileInfo. Unless it is an .exe or .ico file (and perhaps a few more) the icon will be the same for the same file extension, so when you show a dir list you can use the same icon for files of the same type and you don't have to call (and wait for) SHGetFileInfo again.