我正在编写一个Windows窗体应用程序,我需要以编程的方式返回桌面。
我尝试了这段代码,但它没有起作用:
using System;
using System.Windows.Forms;
private void ToggleDesktop() {
SendKeys.Send("^({ESC}D)"); //<-- Semantic error, Should simulate: WIN+D
}
有可能做到这个吗?
我正在编写一个Windows窗体应用程序,我需要以编程的方式返回桌面。
我尝试了这段代码,但它没有起作用:
using System;
using System.Windows.Forms;
private void ToggleDesktop() {
SendKeys.Send("^({ESC}D)"); //<-- Semantic error, Should simulate: WIN+D
}
有可能做到这个吗?
Shell32.dll
Windows程序集来完成这个任务。C:\Windows\System32\Shell32.dll
,然后进入引用属性,在 Embed Interop Types
旁边放置一个 False
(因为你要使用的类是交互式的 ShellClass
)。Shell32.ShellClass objShel = new Shell32.ShellClass();
objShel.ToggleDesktop();
同样适用于 Windows 8.1(已测试):
添加 COM 引用到 "Microsoft Shell Controls and Automation"
(c:\windows\system32\shell32.dll)
然后:
using Shell32;
Shell shellObject = new Shell();
shellObject.ToggleDesktop(); // WinXp: ((Shell32.IShellDispatch4)shellObject).ToggleDesktop();