Windows フォルダー オプションの設定を実装する WPF C# プロジェクトがあります。それらの 1 つは、「シングルクリックで項目を開く」(ダブルクリックではなく) です。そのためにレジストリ キーを変更するときは、解決策を見つけた Windows エクスプローラーを更新する必要があります。ただし、デスクトップは更新されず、手動で更新しても変更は適用されません。メソッドを使用しましIActiveDesktop::ApplyChanges
たが、機能しませんでした (または、間違えた可能性があります)。このコード スニペットも使用しましたが、行った変更はまだ適用されません。
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
Windows エクスプローラーを更新するために使用した完全なコード スニペットを次に示します (これはこのサイトからのものです)。
[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 エクスプローラーでは機能しますが、デスクトップでは機能しません (デスクトップもエクスプローラーに依存するため、これは奇妙です)。変更を有効にするには、デスクトップを再ロードする方法を教えてください。