Show Desktop Window using Type.InvokeMember inC#

dynamic_sysop

Well-known member
Joined
Oct 1, 2002
Messages
1,039
Location
Ashby, Leicestershire.
ive been doing a bit of work with types and InvokeMember and have built a simple example which minimizes all windows ( show desktop ) and restores the windows on a seperate button.
i thought it may come in handy if people want to understand the basics of InvokeMember.
I have built some more complex stuff such as ShDocVw.InternetExplorer , with custom sizes , no toolbar options etc... , but i thought a simple example would be more use.
the code goes like this .....
C#:
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);
        }
included is a sample source ( without binaries ) ;)
 

Attachments

Back
Top