相关疑难解决方法(0)

如何刷新/重新加载桌面

我有一个WPF C#项目,我正在实现Windows文件夹选项的设置.其中之一是"单击以打开项目"(而不是双击).当我更改注册表项时,我需要刷新我找到解决方案的Windows资源管理器.但桌面不刷新,甚至手动刷新它不会应用更改.我使用过IActiveDesktop :: ApplyChanges方法,但没有用(或者我犯了一个错误).我也使用过这段代码片段,但它仍然没有应用我所做的更改:

SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
Run Code Online (Sandbox Code Playgroud)

这里是我用来刷新Win Explorer的完整代码片段(女巫来自这个网站):

[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, …
Run Code Online (Sandbox Code Playgroud)

c# wpf desktop

9
推荐指数
1
解决办法
7616
查看次数

标签 统计

c# ×1

desktop ×1

wpf ×1