撰寫程式完成顯示桌面的功能
顯示桌面的功能,如何透過程式碼作實現? 只要透過 Shell.Application 執行 ToggleDesktop 方法即可
ToggleDesktop 的功能就是顯示桌面,有興趣的可以參考MSDN的說明
http://msdn.microsoft.com/en-us/library/bb774124(VS.85).aspx
VB.NET Code
1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
2 Dim clsidShell As New Guid("13709620-C279-11CE-A49E-444553540000")
3 Dim shell As Object = Activator.CreateInstance( _
4 Type.GetTypeFromCLSID(clsidShell))
5 shell.ToggleDesktop()
6 End Sub
2 Dim clsidShell As New Guid("13709620-C279-11CE-A49E-444553540000")
3 Dim shell As Object = Activator.CreateInstance( _
4 Type.GetTypeFromCLSID(clsidShell))
5 shell.ToggleDesktop()
6 End Sub
C# Code
1 private void button1_Click(object sender, EventArgs e)
2 {
3 Type shellType = Type.GetTypeFromProgID("Shell.Application");
4 object shellObject = System.Activator.CreateInstance(shellType);
5 shellType.InvokeMember("ToggleDesktop", System.Reflection.BindingFlags.InvokeMethod, null, shellObject, null);
6 }
2 {
3 Type shellType = Type.GetTypeFromProgID("Shell.Application");
4 object shellObject = System.Activator.CreateInstance(shellType);
5 shellType.InvokeMember("ToggleDesktop", System.Reflection.BindingFlags.InvokeMethod, null, shellObject, null);
6 }
參考
http://www.zu14.cn/2009/03/19/csharp-shell-system-swith-to-desktop/