Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
761 views
in Technique[技术] by (71.8m points)

winapi - How can I programmatically refresh Windows Explorer?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...