刷新Windows资源管理器在Win7资源管理器、Windows

2023-09-02 21:44:40 作者:苦笑流年记忆

我的程序集HKCU 软件微软的Windows CurrentVersion Explorer中高级隐藏。 Hovewer我不能刷新浏览器,考虑到这种变化。我尝试过:

My program sets "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced" value "Hidden". Hovewer I'm not able to refresh the explorer to take into account this change. I've tried:

1)

    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);` 

2)

    SHELLSTATE state = new SHELLSTATE(); 
    state.fShowAllObjects = (uint)1; 
    SHGetSetSettings(ref state, SSF.SSF_SHOWALLOBJECTS, true); 

3)

    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 5000, ref dwResult); 

4)

    SendMessage(HWND_BROADCAST, WM_COMMAND, 28931 /* Refresh */, 0); 

没有什么工作。所以,我应该怎么办?如果我刷新浏览器自己与F5,然后它的作品。 Hovewer我想了一些优雅的解决方案,因此这将刷新显示无处不在,即使在打开文件 / SAVEFILE 对话框,其中当前打开。

Nothing works. So what should I do? If I refresh Explorer myself with F5, then it works. Hovewer I would like some elegant solution, so it would refresh the display everywhere, even in OpenFile/SaveFile dialogs, which are currently open.

我使用C#.NET,Win7的。

I'm using C# .NET, Win7.

由于安德斯指出,有一个简单的方法使用COM刷新浏览器窗口:

As Anders pointed out, there is a simple way to refresh explorer windows using 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();

所以这部分就完成了。 Hovewer我还需要刷新打开文件 / SAVEFILE 对话和code上面并没有做到这一点。是否有人知道如何刷新这些对话?

So this part is done. Hovewer I still need to refresh the OpenFile/SaveFile dialogs, and the code above doesn't do that. Does anybody know how to refresh those dialogs?

这是很重要的一点是,如果我改变显示隐藏文件,在控制面板文件夹选项,那些打开文件 / SAVEFILE 对话框不被系统刷新,我必须使用F5键手动刷新它们。我只是在寻找一种方法如何刷新所有那些使用C#的对话,所以我并不需要preSS F5了...

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. I'm just looking for a method how to refresh all those dialogs using C#, so I don't need to press F5 anymore...

好了,新的问题与code以上 - 它刷新不仅是探险家的窗户,而且互联网的探险家......不知道如何刷新窗口探险家ONLY

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资源管理器窗口,并没有足够的一个代表来添加评论这样认为我ð提交作为一个答案来帮助你,因为这个问题帮了我。

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.

        // 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);
            }
        }
 
精彩推荐
图片推荐