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

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

问题描述

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

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有点像将资源管理器组合成头.它会导致整个桌面刷新异常,并导致所有打开的资源管理器窗口松动,使滚动位置松动.有没有那么少暴力的东西?

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天全站免登陆