我有一个WPF C#项目,我正在实现Windows文件夹选项的设置。其中之一是“单击打开一个项目”(而不是双击)。当我为这个问题更改注册表项时,我需要刷新我找到解决方案的Windows资源管理器。但是桌面不会刷新,甚至手动刷新也不会应用更改。 我已经使用IActiveDesktop :: ApplyChanges方法,但没有工作(或者我犯了一个错误)。我也用这个代码片断,但它仍然不适,我所做的更改:如何刷新/重新加载桌面
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
这里是我用来刷新赢资源管理器(巫完整的代码片段是从本网站):
[System.Runtime.InteropServices.DllImport("Shell32.dll")]
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
public static void RefreshWindowsExplorer()
{
// Refresh the desktop
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
// Refresh any open explorer 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 Explorer, without checking for the name this could refresh open IE windows
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);
}
}
}
,对于Windows资源管理器的工作原理,但不是桌面(这是奇怪,因为桌面取决于探险太)。 那么我应该如何重新加载桌面,以便我的更改生效?
如果您尝试终止所有资源管理器实例并创建一个新实例,该怎么办? – master131
@ master131,这是行得通的,但这不是一个选项,因为用户将失去所有的资源管理器窗口。 – SepehrM
可能的重复[如何使“显示/隐藏桌面图标”设置生效?](http://stackoverflow.com/questions/3326062/how-do-i-make-the-show-hide-desktop -icons-setting-take-effect) –