Solved

Rebuilding the Windows Icon Cache

Posted on 2001-07-01
5
862 Views
Last Modified: 2007-12-19
Does anyone have any clues about how to programmatically rebuild the Icon Cache.
I am currently involved with developing an upgrade of a program. This new version has a new icon, so I want the program to be able to rebuild the Icon Cache when it is first installed so the old shortcuts get the new icon...

I don't want to delete the SHELLICONCACHE file. Anyone know how TweakUI does it???

Cheers,
Greg
0
Comment
Question by:gwhite012597
  • 3
5 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 6243366
hi,
you can use this procedure to rebuild the icons:

Regards Barry

uses registry;

procedure RebuildIcons;
var
  Registry: TRegistry;
  OldSize: integer;
 dwResult: cardinal;
const
  SShellIconSize = 'Shell Icon Size';
  Timeout = 1000;
begin
  Registry := TRegistry.Create;
  try
    if not Registry.OpenKey('Control Panel\Desktop\WindowMetrics', False)
then
      MessageBeep(0);
    if Registry.ValueExists(SShellIconSize) then
      OldSize := StrToInt(Registry.ReadString(SShellIconSize))
    else
      OldSize := 0;
    Registry.WriteString(SShellIconSize, IntToStr(OldSize + 1));
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
      SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, Timeout, dwResult);
    if OldSize > 0 then
      Registry.WriteString(SShellIconSize, IntToStr(OldSize))
    else
      Registry.DeleteValue(SShellIconSize);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
      SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, Timeout, dwResult);
    Registry.CloseKey;
  finally
    Registry.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RebuildIcons;
end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 6243378
timeout may want to be longer (5000) maybe ..
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6243379
Uses ShlObj;

  SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_FLUSHNOWAIT or SHCNF_FLUSH or SHCNF_PATH,nil,nil);
  SHChangeNotify(SHCNE_UPDATEIMAGE,SHCNF_FLUSHNOWAIT or SHCNF_FLUSH or SHCNF_PATH,nil,nil);
0
 
LVL 17

Expert Comment

by:inthe
ID: 6243385
impressive ;-)
0
 

Author Comment

by:gwhite012597
ID: 6247958
Thanks for the help. Both answers are good. I think I prefer the two liner :) but I'm going split the points. Is that OK with you guys??

Cheers,
Greg
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

17 Experts available now in Live!

Get 1:1 Help Now