/*
27-04-2004 - Salvatore Meschini
http://smeschini.altervista.org/
Vi siete mai chiesti in che modo l'icona "Mostra Desktop",
posta nella barra QuickLaunch di Windows, riesca a mostrare
il Desktop?
La documentazione in merito è scarsa e mancano gli esempi,
per colmare questa lacuna ho scritto un programmino in C#! :-)
Il cuore del programma è formato da 2 sole righe:
Shell32.ShellClass MiaShell = new Shell32.ShellClass();
((Shell32.IShellDispatch4) MiaShell).ToggleDesktop();
L'oggetto utilizzato è IShellDispatch4, il quale estende
IShellDispatch3 (e così via fino a IShellDispatch...)
L'oggetto Shell è molto potente, vi consiglio di
leggere attentamente la documentazione e di fare qualche
esperimento!
Istruzioni per la compilazione dell'esempio:
1) Create un riferimento alla libreria SHELL32.DLL
2) Digitate csc /target:winexe Form1.cs /r:interop.shell32.dll
(oppure affidatevi al vostro IDE di fiducia!)
*/
using System;
using System.Windows.Forms;
using System.Threading;
namespace MostraDesktop
{
public class MiaForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button MostraBtn;
private System.ComponentModel.Container components = null;
public MiaForm()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.MostraBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
this.MostraBtn.Location = new System.Drawing.Point(8, 8);
this.MostraBtn.Name = "MostraBtn";
this.MostraBtn.Size = new System.Drawing.Size(248, 72);
this.MostraBtn.TabIndex = 0;
this.MostraBtn.Text = "Mostra Desktop";
this.MostraBtn.Click += new System.EventHandler(this.MostraBtn_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(264, 86);
this.Controls.Add(this.MostraBtn);
this.Name = "MiaForm";
this.Text = "Salvatore Meschini";
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new MiaForm());
}
private void MostraBtn_Click(object sender, System.EventArgs e)
{
// Non dimenticate il riferimento alla libreria SHELL32.DLL!
Shell32.ShellClass MiaShell = new Shell32.ShellClass();
// Ecco il DESKTOP in tutta la sua bellezza:
((Shell32.IShellDispatch4) MiaShell).ToggleDesktop();
}
}
}
In Delphi avrei scritto:
procedure MinimizzaTutte;
// Minimize All - Sal
var
Wnd: Integer;
begin
Wnd := FindWindow('Shell_TrayWnd', nil);
PostMessage(Wnd, $0111, 419, 0); // WM_COMMAND = $0111
ShowWindow(Wnd, SW_HIDE);
end;
Click here - Clicca qui