Solved

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

Posted on 2003-10-22
4
249 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
jhance, Thanks for your answer to make my first question a happy one.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

12 Experts available now in Live!

Get 1:1 Help Now