IntPtr hWnd = GetWindow(GetWindow(FindWindow("Progman", "Program Manager"), GetWindow_Cmd.GW_CHILD), GetWindow_Cmd.GW_CHILD)
Here is a function that calls the above code and returns true if the window is visible, false if not. : this() // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".ĬbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO))) Private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi) To test to see if icons are visible or not, you can query for the WS_VISIBLE style by using the GetWindowInfo function, shown below: "FolderView" is the actual window that contains the icons.
This sends a message to the SHELLDLL_DefView child window of Progman, which tells it to toggle visibility (by adding or removing the WS_VISIBLE style) of it's only child, "FolderView". SendMessage(hWnd, WM_COMMAND, toggleDesktopCommand, IntPtr.Zero) IntPtr hWnd = GetWindow(FindWindow("Progman", "Program Manager"), GetWindow_Cmd.GW_CHILD) Var toggleDesktopCommand = new IntPtr(0x7402) static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam) static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd) static extern IntPtr FindWindow(string lpClassName, string lpWindowName) Here is sample code in C# that will toggle desktop icons.