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);

http://www.cnblogs.com/conkis/

转载于:https://www.cnblogs.com/conkis/archive/2013/06/02/3114091.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值