今天有人问我:“用shell打开文件(显示桌面.scf)的方式还是用模拟键盘(Win+D)显示桌面” 这应该有更好的方法,就搜了搜,关键字定位“ToggleDesktop” 因为显示桌面.scf的内容是: [Shell] Command=2 IconFile=explorer.exe,3 [Taskbar] Command=ToggleDesktop
找到了MSDN http://msdn.microsoft.com/en-us/library/bb774124(VS.85).aspx 给出的是VB脚本和Javascript脚本,这个容易翻译: JavaScript
- <script language="JScript">
- function fnIShellDispatch4ToggleDesktopJ()
- {
- var objShell = new ActiveXObject("Shell.Application");
-
- objShell.ToggleDesktop();
- }
- </script>
- uses ComObj;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- vShellApplication: OleVariant;
- begin
- vShellApplication := CreateOleObject('Shell.Application');
- vShellApplication.ToggleDesktop;
- end;
补充一个C#的写法:
- private void button1_Click(object sender, EventArgs e)
- {
- Type oleType = Type.GetTypeFromProgID("Shell.Application");
- object oleObject = System.Activator.CreateInstance(oleType);
- oleType.InvokeMember("ToggleDesktop", BindingFlags.InvokeMethod, null, oleObject, null);
- }
-
http://blog.csdn.net/zswang/article/details/2853295
|
请发表评论