[英]Refresh Windows Explorer in Win7
My program sets "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"
value "Hidden"
. 我的程序设置
"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"
值"Hidden"
。 Hovewer I'm not able to refresh the explorer to take into account this change. Hovewer我无法刷新资源管理器以考虑此更改。 I've tried:
我试过了:
1) 1)
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);`
2) 2)
SHELLSTATE state = new SHELLSTATE();
state.fShowAllObjects = (uint)1;
SHGetSetSettings(ref state, SSF.SSF_SHOWALLOBJECTS, true);
3) 3)
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 5000, ref dwResult);
4) 4)
SendMessage(HWND_BROADCAST, WM_COMMAND, 28931 /* Refresh */, 0);
Nothing works. 什么都行不通。 So what should I do?
所以我该怎么做? If I refresh Explorer myself with F5, then it works.
如果我用F5自己刷新资源管理器,那么它可行。 Hovewer I would like some elegant solution, so it would refresh the display everywhere, even in
OpenFile
/ SaveFile
dialogs, which are currently open. Hovewer我想要一些优雅的解决方案,所以即使在当前打开的
OpenFile
/ SaveFile
对话框中,它也会刷新显示器。
I'm using C# .NET, Win7. 我正在使用C#.NET,Win7。
As Anders
pointed out, there is a simple way to refresh explorer windows using COM: 正如
Anders
指出的,有一种使用COM刷新资源管理器窗口的简单方法:
Guid CLSID_ShellApplication = new Guid("13709620-C279-11CE-A49E-444553540000");
Type shellApplicationType = Type.GetTypeFromCLSID(CLSID_ShellApplication, true);
dynamic shellApplication = Activator.CreateInstance(shellApplicationType);
dynamic windows = shellApplication.Windows();
for (int i = 0; i < windows.Count; i++)
windows.Item(i).Refresh();
So this part is done. Hovewer I still need to refresh the 所以这一部分已经完成。
OpenFile
/ SaveFile
dialogs, and the code above doesn't do that. Hovewer我仍然需要刷新
OpenFile
/ SaveFile
对话框,上面的代码不会这样做。 Does anybody know how to refresh those dialogs? 有人知道如何刷新这些对话框吗?
An important point is that if I change the "Show Hidden Files" in Folder Options in Control panel, those OpenFile
/ SaveFile
dialogs are not refreshed by the system, I must refresh them manually using F5. 重要的一点是,如果我在“控制面板”中的“文件夹选项”中更改“显示隐藏文件”,系统不会刷新那些
OpenFile
/ SaveFile
对话框,我必须使用F5手动刷新它们。 I'm just looking for a method how to refresh all those dialogs using C#, so I don't need to press F5 anymore... 我只是在寻找一种方法如何使用C#刷新所有这些对话框,所以我不再需要再按F5了...
Ok, so new problem with the code above - it refresh not only windows explorers, but also internet explorers... Any idea how to refresh windows explorers ONLY? 好吧,所以上面的代码出现了新的问题 - 它不仅刷新了Windows资源管理器,还刷新了互联网资源管理器...任何想法如何刷新Windows资源管理器?
I figured out a way to check if the windows was a Windows Explorer window, and don't have enough of a rep to add a comment so thought I'd submit it as an answer to help you out because this question helped me out. 我找到了一种方法来检查Windows是否是Windows资源管理器窗口,并且没有足够的代表来添加评论,所以我认为我会将其作为答案提供帮助,因为这个问题帮助了我。
// based on http://stackoverflow.com/questions/2488727/refresh-windows-explorer-in-win7
Guid CLSID_ShellApplication = new Guid("13709620-C279-11CE-A49E-444553540000");
Type shellApplicationType = Type.GetTypeFromCLSID(CLSID_ShellApplication, true);
object shellApplication = Activator.CreateInstance(shellApplicationType);
object windows = shellApplicationType.InvokeMember("Windows", System.Reflection.BindingFlags.InvokeMethod, null, shellApplication, new object[] { });
Type windowsType = windows.GetType();
object count = windowsType.InvokeMember("Count", System.Reflection.BindingFlags.GetProperty, null, windows, null);
for (int i = 0; i < (int)count; i++)
{
object item = windowsType.InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, null, windows, new object[] { i });
Type itemType = item.GetType();
// only refresh windows explorers
string itemName = (string)itemType.InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, item, null);
if (itemName == "Windows Explorer")
{
itemType.InvokeMember("Refresh", System.Reflection.BindingFlags.InvokeMethod, null, item, null);
}
}
I don't know about Open/Save dialogs, but you can get a list of open explorer windows with COM automation, the Shell.Application object has a collection of windows , or CoCreate IID_IShellWindows directly, each window in the list has a refresh method. 我不知道打开/保存对话框,但你可以获得一个带有COM自动化的开放资源管理器窗口列表, Shell.Application对象有一个窗口集合 ,或直接CoCreate IID_IShellWindows,列表中的每个窗口都有一个刷新方法。
WSH/JScript: WSH / JScript的:
for(var sw=new ActiveXObject("Shell.Application").Windows(),i=0;i<sw.Count; ++i)
sw.Item(i).Refresh();
I don't know about C#, but here are examples dealing with shell windows in WSH/JScript and c++ 我不知道C#,但这里有一些处理WSH / JScript和c ++中的 shell窗口的例子
当您安装注册文件类型的应用程序时,资源管理器窗口通常会刷新以指示新关联 - 您是否可以监视安装程序正在进行的API调用以查看它是如何刷新窗口的?
With Windows 10 having changed the name of the Explorer window: Windows 10更改了Explorer窗口的名称:
if ((itemName == "Windows Explorer") || (itemName == "File Explorer")) {
itemType.InvokeMember("Refresh", System.Reflection.BindingFlags.InvokeMethod, null, item, null);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.