C# 刷新资源管理器
在我的程序中,我切换隐藏文件的注册表值以告诉资源管理器是否隐藏或显示它们。但是,由于资源管理器不会自行刷新,因此我发送事件
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
来刷新所有内容。然而,不幸的是,它似乎并没有带来任何令人耳目一新的东西。我看到桌面上的屏幕有点闪烁,但为了看到更改,我必须手动刷新文件夹。 SHChangeNotify 似乎不适合我。任何帮助将不胜感激。
In my program I toggle the registry value of hidden files to tell explorer whether to hide or show them. However, since explorer doesn't refresh on it's own, I send the event
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
to refresh everything. However, it doesn't seem to be refreshing anything unfortunately. I see the screen on the desktop flicker a bit, but in order to see the changes, I have to manually refresh the folder. SHChangeNotify doesn't seem to be working for me. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行此操作的一种方法是更新注册表设置,然后将 F5 键发送到当前窗口。它只需要很少的代码,但使用 SendKeys 从来都不是理想的选择,它只会更新当前窗口的视图。
更好的方法是使用 SHGetSetSettings API。这将可靠地更新所有资源管理器窗口中的视图,并更新注册表中的设置。下面的代码基于此处发布的答案。
One way to do this is to update the registry settings and then send an F5 key to the current window. It takes very little code, but it's never ideal to use SendKeys and it only updates the view for the current window.
A better method is to use the SHGetSetSettings API. This will reliably update the view in all Explorer Windows and updates the settings in the registry as well. The code below is based on an answer posted here.
尝试使用 SHGetSetSettings 更改 fShowAllObjects
但使用 SHGetSetSettings 进行简单的获取和设置将不起作用。
它足够智能,可以将当前设置与您发送的设置进行比较,并且只有在两者不同时才会通知其他窗口更改。
要刷新桌面,请使用 IShellWindows 枚举 shell 窗口,请检查 IWebBrowser2.FullName 属性以跳过 IE 窗口,然后调用 IWebBrowser2::Refresh。
Try SHGetSetSettings with your change to fShowAllObjects
A simple Get and Set with SHGetSetSettings won't work though.
It's smart enough to compare it's current settings to what your sending it and will only notify other windows of the change if the two are different.
To refresh the desktop use IShellWindows to enumerate shell windows, check the IWebBrowser2.FullName property to skip IE windows and then call IWebBrowser2::Refresh.