2

I been trying to hide my Desktop Icons similar to right clicking on Desktop > View Hide Desktop Icon. I found some ways to do it using C# or C++ but it does not take effect until you restart the computer.

Is there a way I could do it without restarting similar to how windows does it. Also I found some that used winAPI and shell, if you could help me use one of those too I would be grateful. Here's the many code I've tried so far:

private const int SW_HIDE = 0;
private const int SW_SHOW = 5;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

public static void Main( string[] args ){
      //.... Irrelevant code ...

      Console.Writeline(" Goodbye Icons ");
      IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null);
      ShowWindow(hWnd, SW_HIDE);

      //.... Irrelevant code....
      // ShowWindow(hWnd, SW_SHOW); //This undoes the disable desktop
}
SubjectiveKirby
  • 168
  • 1
  • 15
Sam Rafiei
  • 73
  • 8
  • You don't have to restart your computer. Just explorer.exe. – itsme86 Aug 17 '18 at 14:54
  • https://stackoverflow.com/questions/6402834/how-to-hide-desktop-icons-programatically – itsme86 Aug 17 '18 at 14:55
  • @itsme86 I tried that, but I think I didn't do it right or I did it on a code that didn't work, ill reply in 30 min, I'm going to try and see if it works, Thank you for your response – Sam Rafiei Aug 17 '18 at 15:04
  • 1
    @itsme86 thank you so much bro, It worked, Ill put an answer up with the code I used. Thanks Again :))) – Sam Rafiei Aug 17 '18 at 15:07
  • Closing as dupe based on OP's words. – SergeyA Aug 17 '18 at 15:08
  • BTW, this is not C++. 1) C++ does not have access specifiers, like `public` on free standing functions. 2) The start of a program is `main`, not `Main`. I suggest adjusting the language tags accordingly. – Thomas Matthews Aug 17 '18 at 15:33
  • You don't need to restart computer nor explorer.exe. You can use the shell API to toggle desktop icons in realtime. I'm going to add an answer with a C++ example to the "dupe". – zett42 Aug 17 '18 at 15:46
  • @zett42 well if you have a better way I'm all up for it, cause I been trying for 50 min to figure out how to restart explorer.exe through C# without it opening file manager instead :/ – Sam Rafiei Aug 17 '18 at 16:03
  • I have added an [answer that uses the official shell API only](https://stackoverflow.com/a/51899584/7571258). – zett42 Aug 17 '18 at 16:30
  • @zett42 Thank you, ill check it out right now :) – Sam Rafiei Aug 17 '18 at 16:40
  • It is for the COM smart pointers. Try to replace that by – zett42 Aug 17 '18 at 16:44

0 Answers0