How can I know whether the next SHGetFileInfo (SHGFI_ICON) call will be slow (for exe files etc.)?

StackOverflow https://stackoverflow.com/questions/23077457

  •  03-07-2023
  •  | 
  •  

문제

I am writting a file manager. When it opens, the UI freezes for a while. I profiled it and find the slow function is SHGetFileInfo.

SHFILEINFO shinfo;
SHGetFileInfo(FullPath.c_str(), NULL, &shinfo, sizeof(shinfo),
    SHGFI_ICON | SHGFI_LARGEICON))

Also, the program runs fast enough even when there are hundreds of folders, but becomes extremely slow when there is at least one executable. I think loading icon from such files is a heavy task since the resources must be loaded.

I see that when Windows Explorer loads a folder, all icons except executables are correct, and executables have their default icons (the icon of command line utilities). Then their icons become correct in a few seconds.

My question is how can Explorer determine which icons are fast to load and which are slow? I think checking for the extension .exe is not reliable because one may do assoc .foo=exefile or set another extension's icon to %1, etc.

도움이 되었습니까?

해결책

The Windows shell uses a couple of mechanisms to deal with this performance hit:

  1. It looks up icons in a background thread. Explorer is still perfectly usable whilst this thread is doing its work.
  2. Explorer caches icons. This means that the icon extraction is performed once only and the result is remembered.

I think if you want your file manager to be as usable as Explorer then you will need to implement similar optimisations. Or perhaps SHGetFileInfo already takes advantage of the system icon cache.

These articles relating to shell icon performance may be useful to you:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top