none
Showing the desktop

    Question

  • If you right click on the taskbar you get a drop down menu and one of the options is to show the desktop. It clears all windows and minimizes them all to the taskbar. How do you do that in C#? I want when my program opens to minimize all windows to the taskbar so I can take a screenshot of the entire screen. i already know how to do the screen shot. I just need to know how to minimize all windows to the taskbar.

     

    Tuesday, May 13, 2008 8:37 PM

Answers

All replies

  • You can iterate through open windows and minimize them programmatically. Here is a helper class for working with open windows: Window Tabifier

    Another way them might wokr but I am not sure is to call GetDesktopWindow Function () using P/Invoke to get the handle of desktop window and then show the desktop using either ShowWindow or SetForegroundWindow function.

    Here is a third way: robgruen's WebLog : Programmatically Showing the Desktop
    Tuesday, May 13, 2008 9:11 PM
  • Code Snippet

    class TaskBar {

        [DllImport("user32.dll", SetLastError = true)]

        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

     

        [return: MarshalAs(UnmanagedType.Bool)]

        [DllImport("user32.dll", SetLastError = true)]

        public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

     

        public enum Messages {

            nothing = 0,

            DisplayStartupMenu = 305,

            DisplayRunDialog = 401,

            DisplayLogoffDialog = 402,

            ArrangeCascade = 403,

            ArrangeTileHrz = 404,

            ArrangeTileVrt = 405,

            ShowDesktop = 407,

            ShowDateTimeDialog = 408,

            ShowTaskbarPrps = 413,

            MinAll = 415,

            MaxAll = 416,

            ShowDesktop2 = 419,

            ShowTaskMngr = 420,

            TaskBrCustomizeNtfy = 421,

            LockTaskbar = 424,

            HelpAndSupportCenter = 503,

            ControlPanel = 505,

            TurnOffCompDialog = 506,

            PrintersAndFaxesDialog = 510,

            FindFilesDialog = 41093,

            FindComputers = 41094

        }

     

        public static Boolean SendTaskbarMessage (Messages m) {

            IntPtr hWnd = TaskBar.FindWindow("Shell_TrayWnd", null);

            uint WM_COMMAND = 0x111;

            bool result = TaskBar.PostMessage(hWnd, WM_COMMAND, (IntPtr)m, (IntPtr)Messages.nothing);

     

            return result;

        }

    }

     

     

    Tuesday, May 13, 2008 9:46 PM