PDA

Click to See Complete Forum and Search --> : Show Desktop , Using Type.InvokeMethod.


dynamic_sysop
Dec 10th, 2003, 11:13 AM
here's a simple code i put together showing the use of Type.InvokeMethod. I've built a few complex codes ( for example creating a custom internet explorer object ) , but this is a basic sample to ease people in to how it works.
this will carry out the same function as using the Show Desktop icon on your taskbar.

private Type typeShell=null;
private object objShell=Type.Missing;

private void button1_Click(object sender, System.EventArgs e)
{
// to Minimize all windows on the desktop .
// first we get the type from the Shell . Application
typeShell=Type.GetTypeFromProgID("Shell.Application");
// next we create the object " objShell " from the type " typeShell "
objShell=Activator.CreateInstance(typeShell);
// finally we Invoke " MinimizeAll " to show the desktop
typeShell.InvokeMember("MinimizeAll",System.Reflection.BindingFlags.InvokeMethod,null,objShell,null);
}

private void button2_Click(object sender, System.EventArgs e)
{
// as above but Invoking " UndoMinimizeAll " to restore all the Desktop windows
typeShell=Type.GetTypeFromProgID("Shell.Application");
objShell=Activator.CreateInstance(typeShell);
typeShell.InvokeMember("UndoMinimizeAll",System.Reflection.BindingFlags.InvokeMethod,null,objShell,null);
}

also, i've included a sample source...