Rebuilding the windows icon cache

Submitted on: 1/21/2015 4:21:00 AM
By: Citizen_Suicide (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: VB 6.0
Views: 869
     If you have ever written a program that creates file associations, and has changed the icon associated with these files then this may be of interest. This will tell you how to rebuild the icon cache at runtime, and so display these icons without restarting. I decided to submit this when i tried to find some information on it my self, it took many days of searching to find some very very criptic information on the subject, so i have simplified this and put it up here for you :).

This article has accompanying files
				In windows 32bit all icons being used by the shell are stored in memory in what is known as the icon cache. Ussually this only gets rebuilt when the program starts up (although windows does a little bit of cleaning up of un-used icons at run-time) and so therefore any change to the windows registry default icons does nothing until windows has restarted.
Using the technique listed here you should be able to produce code that can force windows to rebuild this icon cache, and therefore display any changes at run-time.
I must stress that this technique is not perfect and can produce some strange results, i've noticed that it can make the little shortcut arrow icon appear as a blank box 'behind' the shortcut icon. It's up to you whether you want to use this code or let the user wait to reboot before they see your changes to thier icons.
As it appears there is no single windows api to achieve this, because of this you have to be a little bit clever :)
To do this you must follow these steps:
(1) Get the value held in "HKEY_CURRENT_USERControl Panel\Desktop\WindowMetrics Registry key".
You'll want the value held in "Shell Icon Size" (if this throws up an error try "Shell Icon BPP")
(2) Subtract 0ne from this number
(3) Write the number back to the registry
(4) Call SendMessageTimeout HWND_BROADCAST
(5) Reset the key to its original setting
(6) call SendMessageTimeout HWND_BROADCAST once again
Thats it! Theres plenty of articals and source code on this site to change registry entries just do a quick search.
The *.zip has some of the api declares and some code snippets you may find usefull.

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net

Other 2 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.