如何以编程方式刷新 Windows 资源管理器?

发布于 2024-07-14 15:05:44 字数 1201 浏览 10 评论 0原文

我有一个使用 IShellIconOverlayIdentifier 接口的 Windows shell 扩展在文件和文件夹上显示覆盖图标。 我的扩展有点像 TortoiseCVSTortoiseSVN

有时我需要让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小清晰的声音 2024-07-21 15:05:44

有人知道该怎么做吗
这样更好吗?

我个人不知道。 您提到 Tortoise 程序执行类似的操作,因此一个很好的起点是查看它们在源代码中执行的操作:)

这些看起来是处理此问题的相关源文件:

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

  1. 将 shell 图标大小或颜色深度设置为临时值,
  2. 来更新所有窗口
  3. 通过广播设置更改重置 shell 图标大小或颜色深度恢复为原始值,
  4. 并通过广播设置更改第二次更新所有窗口,

也许这是在 XP 中正常运行的技巧的一部分。

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.

荒路情人 2024-07-21 15:05:44

使用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.

一影成城 2024-07-21 15:05:44

您还可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文