如何从 C# 以编程方式(即 F5)刷新 Windows 桌面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/647270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to refresh the windows desktop programmatically (i.e. F5) from C#?
提问by DSO
Yeah, I know this seems like a dumb question, its just a one-off hack I need to wrap up a somewhat mundane task so I can move on to something more interesting.
是的,我知道这似乎是一个愚蠢的问题,这只是一个一次性的技巧,我需要完成一项有点平凡的任务,这样我才能继续做更有趣的事情。
EDIT: Maybe more info would help: I'm trying to remove some shortcuts from the desktop and I need the user to see it removed right away (so they don't have to press F5).
编辑:也许更多信息会有所帮助:我正在尝试从桌面删除一些快捷方式,我需要用户立即看到它被删除(因此他们不必按 F5)。
采纳答案by Tom Anderson
You can use the SHChangeNotifyAPI.
您可以使用SHChangeNotifyAPI。
[System.Runtime.InteropServices.DllImport("Shell32.dll")]
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
and then call it this way
然后这样称呼它
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
回答by John T
I think you're looking for IActiveDesktop::ApplyChanges. You will need to access this via the COM interface, which should be fairly easy with all the documentationMicrosoft provides on COM Interop.
我认为您正在寻找IActiveDesktop::ApplyChanges。您将需要通过 COM 接口访问它,使用Microsoft 在 COM Interop 上提供的所有文档,这应该相当容易。