English 中文(简体)
How to hide desktop icons by double clicking the desktop using c#
原标题:

I wanted to know if there is a way to toggle desktop icon to show/hide when the desktop is double clicked. Similar to how it is done in Stardock Fences. I wanted it to be done using visual c#.

问题回答

The second part of your question (when the desktop is double-clicked) is relative simple. You need to install an application-defined hook procedure into a hook chain. Sounds pretty difficult, but is explained in detail in the code sample found here. You may want to download the source here (requires a free account there).

For the first part, the hiding/unhiding of desktop icons, I found several similar code samples like this, however, none seem to work on my pc so you might want to look for another solution to that problem.

For hiding the desktop icons there is a registry key (have a look here).

I guess you will have to restart your explorer after that to apply the changes by using

        Process[] proc = Process.GetProcessesByName("Explorer");
        foreach(Process p in proc)
            p.Kill();

        Process.Start("explorer.exe");

i dont know how you would show/hide the desktop icons using C#, however i have read a few articles about how to do it using the resistry keys. the problem with using the registry keys method is that the "Explorer.exe" process would have to be restarted in order for the changes to take affect. luckily i found a code sample online that does just that:

On Error Resume Next

  Kill Explorer.exe

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name =  explorer.exe ")

For Each objProcess in colProcessList
objProcess.Terminate(1)
Next

  Launch Explorer.exe

Set objShell = CreateObject("Wscript.Shell") 

objShell.Run "explorer.exe" 

Set objShell = Nothing

Wscript.exit

That script will quickly restart the "Explorer.exe" process without logging the current user off.... Hope it Helps!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签