如何以编程方式刷新 Windows 资源管理器? [英] How can I programmatically refresh Windows Explorer?

查看:52
本文介绍了如何以编程方式刷新 Windows 资源管理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows shell 扩展,它使用 IShellIconOverlayIdentifier 在文件和文件夹上显示覆盖图标的界面.我的扩展有点像 TortoiseCVSTortoiseSVN.

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.

有时我需要让 Windows 资源管理器重绘它的所有图标.为此,我像这样调用 SHChangeNotify:

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.

所以我尝试像这样发送 WM_SETTINGCHANGE:

So I tried sending WM_SETTINGCHANGE like this:

SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0) 

在 Vista 上,这会刷新文件夹树,但不会刷新右侧窗格.

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

SHChangeNotify() 后跟 WM_SETTINGCHANGE 的组合似乎在 Vista 上工作得很好.但是如果显示,我仍然无法在 XP 上刷新文件夹树.

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?

有没有更好的 XP 解决方案?

Is there a better solution for XP?

发送SHCNE_ASSOCCHANGED 有点像在头顶上击打 Explorer.它会导致整个桌面非常猛烈地刷新,并导致任何打开的资源管理器窗口失去滚动位置.有没有什么不那么暴力的东西?

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?

推荐答案

有没有人有任何想法怎么做这样更好吗?

Does anyone have any ideas how to do this better?

我个人不知道.你提到了做类似事情的 Tortoise 程序,所以一个很好的起点是看看他们在他们的源代码中做了什么:)

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:

  • TortoiseCVS - ShellUtils.cpp
  • TortoiseSVN - ShellUpdater.cpp (username: "guest", password: "")

我在 RebuildIcons 方法中注意到每个将:

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

  1. 将外壳图标大小或颜色深度设置为临时值
  2. 通过广播设置更改来更新所有窗口
  3. 将外壳图标大小或颜色深度重置为原始值
  4. 通过广播设置更改再次更新所有窗口

也许这是让事情在 XP 中工作的技巧的一部分.

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

这篇关于如何以编程方式刷新 Windows 资源管理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆