Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for all your replies and comments. I finally figured out a workaround for this problem. We could just hide all desktop icons and then show them again. This will force the desktop to reload. </p> <p><strong>Update:</strong> In Window 8, <code>SHELLDLL_DefView</code> is the child of one of <code>WorkerW</code> windows. (instead of <code>Progman</code>) So here is the updated code which works on Windows 8 and 8.1 too: </p> <pre><code> [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", SetLastError = true)] static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); enum GetWindow_Cmd : uint { GW_HWNDFIRST = 0, GW_HWNDLAST = 1, GW_HWNDNEXT = 2, GW_HWNDPREV = 3, GW_OWNER = 4, GW_CHILD = 5, GW_ENABLEDPOPUP = 6 } private const int WM_COMMAND = 0x111; [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); [DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount); [DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); public static string GetWindowText(IntPtr hWnd) { int size = GetWindowTextLength(hWnd); if (size++ &gt; 0) { var builder = new StringBuilder(size); GetWindowText(hWnd, builder, builder.Capacity); return builder.ToString(); } return String.Empty; } public static IEnumerable&lt;IntPtr&gt; FindWindowsWithClass(string className) { IntPtr found = IntPtr.Zero; List&lt;IntPtr&gt; windows = new List&lt;IntPtr&gt;(); EnumWindows(delegate(IntPtr wnd, IntPtr param) { StringBuilder cl = new StringBuilder(256); GetClassName(wnd, cl, cl.Capacity); if (cl.ToString() == className &amp;&amp; (GetWindowText(wnd) == "" || GetWindowText(wnd) == null)) { windows.Add(wnd); } return true; }, IntPtr.Zero); return windows; } static void ToggleDesktopIcons() { var toggleDesktopCommand = new IntPtr(0x7402); IntPtr hWnd = IntPtr.Zero; if (Environment.OSVersion.Version.Major &lt; 6 || Environment.OSVersion.Version.Minor &lt; 2) //7 and - hWnd = GetWindow(FindWindow("Progman", "Program Manager"), GetWindow_Cmd.GW_CHILD); else { var ptrs = FindWindowsWithClass("WorkerW"); int i = 0; while (hWnd == IntPtr.Zero &amp;&amp; i &lt; ptrs.Count()) { hWnd = FindWindowEx(ptrs.ElementAt(i), IntPtr.Zero, "SHELLDLL_DefView", null); i++; } } SendMessage(hWnd, WM_COMMAND, toggleDesktopCommand, IntPtr.Zero); } </code></pre> <p>Now we can just toggle desktop icons twice:</p> <pre><code> ToggleDesktopIcons(); ToggleDesktopIcons(); </code></pre> <p>Hope this helps someone else ...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload