Solved

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

Posted on 2003-10-22
4
250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

862 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now