ToggleDesktopIcons()     //Thanks to https://stackoverflow.com/questions/17503289/how-to-refresh-reload-desktop
        {
            state = new SHELLSTATE();
            var    toggleDesktopCommand = new IntPtr(0x7402);
            IntPtr hWnd = IntPtr.Zero;

            if (Environment.OSVersion.Version.Major < 6 || Environment.OSVersion.Version.Minor < 2) //7 and -
            {
                hWnd = GetWindow(FindWindow("Progman", "Program Manager"), GetWindow_Cmd.GW_CHILD);
            }
            else
            {
                IEnumerable <IntPtr> ptrs = FindWindowsWithClass("WorkerW");
                int i = 0;
                while (hWnd == IntPtr.Zero && i < ptrs.Count())
                {
                    hWnd = FindWindowEx(ptrs.ElementAt(i), IntPtr.Zero, "SHELLDLL_DefView", null);
                    i++;
                }
            }

            SHGetSetSettings(ref state, SSF.SSF_HIDEICONS, false);
            state.fHideIcons = !state.fHideIcons;
            SHGetSetSettings(ref state, SSF.SSF_HIDEICONS, true);

            if (hWnd == IntPtr.Zero)
            {
                //"SHELLDLL_DefView" was not found as a child within WorkerW - Lets check the current ShellWindow
                IntPtr desktop = GetShellWindow();
                hWnd = FindWindowEx(desktop, IntPtr.Zero, "SHELLDLL_DefView", null);
            }

            if (hWnd != IntPtr.Zero)
            {
                SendMessage(hWnd, WM_COMMAND, toggleDesktopCommand, IntPtr.Zero);
            }
        }
Exemple #2
0
 public extern static void SHGetSetSettings(ref SHELLSTATE lpss, SSF dwMask, bool bSet);
Exemple #3
0
		public extern static void SHGetSetSettings(ref SHELLSTATE lpss, SSF dwMask, bool bSet);
 private static extern void SHGetSetSettings(ref SHELLSTATE lpss, SSF dwMask, bool bSet);