Solved

SHGetFileInfo takes a long time to get icon index for html-typed files for the first time

Posted on 2003-10-22
4
258 Views
Last Modified: 2013-11-20
I am writing a window program with CTreeCtrl to display file system in the computer. Both directory and file are displayed in the tree.

I use SHGetFileInfo to retrieve the icon index for the files.

SHFILEINFO sfi;
SHGetFileInfo(filepath, 0, &sfi, sizeof( sfi ), SHGFI_ICON | SHGFI_SMALLICON );

After program starts, if I clicked on a directory with html-typed file(s), it will take 3-5 seconds to display the expanded  tree. If the clicked directory does not contain any html-typed file(s), it will expand almonst instantly. After first time, the following expansion will happen much faster.

Thanks for your help.
0
Comment
Question by:htang_us
  • 2
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 9600407
Indeed this is the case and there is no solution.  Depending on how the EXE files are physically structured, Windows may need to read through the file to locate the icon.  This, obviously, takes time.  You can see this (often annoying) behavior even in Windows Explorer and other Microsoft written apps.

If this is a problem for you, work out a caching scheme yourself so that you don't have to lookup the icons yourself every time.  You could use the ones you have from the cache and only read in any changed or new ones.
0
 
LVL 2

Author Comment

by:htang_us
ID: 9600514
Since SHGetFileInfo retrieves the icon index, the index for html file is 10 on my computer.
However, if I use 10 instead calling SHGetFileInfo, no icon will be displayed (SystemImageList has already be set in the CTreeCtrl.)

Is there anything special to these icon index?

thanks
0
 
LVL 32

Expert Comment

by:jhance
ID: 9600560
The icon index is related to the FILE in question.  So Windows must read the file, locate the 10th icon, and retrieve it.  Depending on where the icon is actually loaded in the file, it can take a while since disk activity is relatively costly in terms of execution time.
0
 
LVL 2

Author Comment

by:htang_us
ID: 9600604
jhance, Thanks for your answer to make my first question a happy one.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question