您的位置:首页 > 运维架构 > Shell

C#使用系统的“显示桌面”功能(Shell.Application)

2009-03-19 10:48 225 查看
在 Windows 系统的 任务栏 上的 快速启动栏 里,通常有一个图标

,点击这个图标,就会切换到桌面。这个图标实际是一个 “Windows Explorer Command” ,用记事本打开这个文件,我们看到如下的内容:

[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop


这个文件的格式,实际是一个 ini 文件的形式,其中,我们要关注的是 Command=ToggleDesktop 这句,这句是explorer要执行的命令;通过 MSDN 我们可以看到关于 ToggleDesktop 的说明:

This method has the same effect as the Show Desktop button in the Quick Launch area of the Taskbar.
It either hides all open windows and shows the desktop, or it hides the desktop and shows all open windows.
The ToggleDesktop method does not display any user interface, it just invokes the toggle action.

在C#中,使用 显示桌面 的功能,实际就是使用 Shell.Application 去执行 ToggleDesktop 这个功能,代码如下:

Type shellType = Type.GetTypeFromProgID("Shell.Application");
object shellObject = System.Activator.CreateInstance(shellType);
shellType.InvokeMember("ToggleDesktop", System.Reflection.BindingFlags.InvokeMethod, null, shellObject, null);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐