Programmatically Showing the Desktop (ToggleDesktop)

Have you ever used the Win+D (Show/Hide Desktop) or Win+M (Minimize All) shortcut keys? Have you ever tried to recreate the shortcuts on your quicklaunch bar? 

Not the easiest thing in the world to find information on. There's one knowledge base article you can use that shows you how to do this, 190355 How to Re-create the Show Desktop Icon on Quick Launch Toolbar, and that's about it. Now imagine trying to find information on this programmatically?

The 1st thing you'd have to know is to search for ToggleDesktop, because searching for Show Desktop doesn't give you any programmatic information. If by some chance you did know to look for ToggleDesktop, you'd probably come accross this MSDN entry: ToggleDesktop Method. Looking at this object however (IShellDispatch4), you don't see any sample source and trying to google the term is even more confusing.

In short, if you want to programmatically show the desktop (tile windows, minimize all windows, run explorer, browse for folders, or any other numerous shell functionality exposed by this object use the following code), set a reference to shell32.dll and use the following code (C#):

// Create an instance of the shell class

            Shell32.ShellClass objShel = new Shell32.ShellClass();

                 

            // Show the desktop

            ((Shell32.IShellDispatch4) objShel).ToggleDesktop();

                 

                  // Do some operations here

            // Restore the desktop

            ((Shell32.IShellDispatch4) objShel).ToggleDesktop();

This should be simple enough to convert to VB.NET...send me feedback if you have any questions.