如何以编程方式刷新 Windows 资源管理器?
我有一个使用 IShellIconOverlayIdentifier 接口的 Windows shell 扩展在文件和文件夹上显示覆盖图标。 我的扩展有点像 TortoiseCVS 或 TortoiseSVN。
有时我需要让 Windows 资源管理器重绘所有图标。 为此,我调用 SHChangeNotify,如下所示:
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL)
这将刷新任何打开的资源管理器窗口的桌面和右侧窗格。 它不会刷新任何资源管理器窗口左侧的文件夹树。
所以我尝试发送 WM_SETTINGCHANGE 像这样:
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0)
在 Vista 上这会刷新文件夹树,但不会刷新右侧窗格。
SHChangeNotify()
和 WM_SETTINGCHANGE
的组合似乎在 Vista 上运行得很好。 但是XP上的文件夹树如果显示的话我还是无法刷新。
有谁知道如何做得更好?
XP有更好的解决方案吗?
发送 SHCNE_ASSOCCHANGED
有点像用棍棒打 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我个人不知道。 您提到 Tortoise 程序执行类似的操作,因此一个很好的起点是查看它们在源代码中执行的操作:)
这些看起来是处理此问题的相关源文件:
我在每个方法的
RebuildIcons
方法中注意到:也许这是在 XP 中正常运行的技巧的一部分。
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:Perhaps this is part of the trick to get things working in XP.
使用spy++查看当您在Windows资源管理器中按F5时发送什么WM_COMMMAND消息或查找用于查看/刷新的菜单消息
然后使用FindWindow获取您想要的资源管理器窗口并将之前记录的WM_COMMAND等消息发送给它。
这是控制各种 Windows 程序的有趣方式。
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.
您还可以使用 F5 键码向所有打开的资源管理器窗口发送 WM_KEYDOWN 消息。 不过,这有点黑客行为。
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.