22

I have a Windows shell extension that uses IShellIconOverlayIdentifier interface to display overlay icons on files and folders. My extension is a little like TortoiseCVS or TortoiseSVN.

Sometimes I need to make Windows Explorer redraw all it's icons. To do this, I call SHChangeNotify like this:

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL)

This refreshes the desktop and right hand pane of any open explorer windows. It doesn't refresh the folder tree on the left hand side of any Explorer windows.

So I tried sending WM_SETTINGCHANGE like this:

SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0) 

on Vista this refreshes the folder tree, but not the right hand pane.

The combination of SHChangeNotify() followed by WM_SETTINGCHANGE seems to work quite well on Vista. But I still can't refresh the folder tree on XP if it is displayed.

Does anyone have any ideas how to do this better?

Is there a better solution for XP?

Sending SHCNE_ASSOCCHANGED is a bit like clubbing Explorer over the head. It causes the whole desktop to refresh quite violently and casues any open Explorer windows to loose there scroll position. Is there anything that's a bit less violent?

2
  • TweakUI for XP has a "repair icon cache" option. You may be able to use SPY++ to see what it does.
    – i_am_jorf
    Commented Mar 15, 2009 at 5:40
  • 1
    HughE ! Were you able to solve your problem?
    – A9S6
    Commented Apr 26, 2009 at 12:42

3 Answers 3

7

Does anyone have any ideas how to do this better?

Personally I don't know. You mention the Tortoise programs which do a similar thing, so an excellent starting point would be to have a look at what they do in their source :)

These look to be the relevant source files that handle this problem:

I note in the RebuildIcons method in each of those will:

  1. set the shell icon size or colour depth to a temporary value
  2. updates all the windows by broadcasting the setting change
  3. resets the shell icon size or colour depth to the original value
  4. updates all the windows a second time with a broadcast of the setting change

Perhaps this is part of the trick to get things working in XP.

3
  • 1
    It is unfortunate there isn't a better way. I hope we're not doing this frequently!
    – i_am_jorf
    Commented Mar 16, 2009 at 2:32
  • @jeffamaphone we're not doing this too frequently. A few times a day most of the time.
    – HughE
    Commented Mar 16, 2009 at 2:42
  • It doesn't look like RebuildIcons is used anymore, but rather SHChangeNotify(SHCNE_UPDATEITEM, ...). This also seems to be what Dropbox does. Do a search on the TortoiseSVN source for SHChangeNotify to see what I mean. Also, be careful to pass the correct SHCNF_PATH parameter (e.g, SHCNF_PATHW for Unicode).
    – kgriffs
    Commented Aug 19, 2009 at 14:52
0

Use spy++ to see what WM_COMMMAND message gets sent when you press F5 in windows explorer or find what menu message is used for view/refresh

Then use FindWindow to get the explorer window you want and send the WM_COMMAND recorded earlier etc message to it.

This is a fun way to control all sorts of Windows programs.

2
  • I tried that but it didn’t show anything useful. It seems to delete all items and then re-add them all. It it definitely not necessary to go to those lengths though because it does “refresh” if you just change the display mode to something else and back. :-|
    – Synetech
    Commented Mar 4, 2012 at 20:04
  • Using Spy++ to track down and try those changes, while technically possible, is a real PITA. You could waste a lot of time if you're not already used to using the tool. Commented Sep 28, 2017 at 18:38
0

You can also send a WM_KEYDOWN message with the F5 keycode to all open explorer windows. This is a bit of a hack though.

1
  • 2
    The simplest way is not the best way in this case.
    – Idan
    Commented Jan 13, 2014 at 11:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.