Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

i've 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 .....

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 ) ;)

minimize all.zip

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...