`
zu14
  • 浏览: 442645 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类

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

阅读更多

在 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);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics