How do I hook Windows desktop folder clicks?
June 27, 2009 2:38 PM   Subscribe

I'd like to write a program for Windows XP that detects when a folder on the desktop is clicked and switches the desktop location to that folder, instead of the default Explorer behavior of opening the folder in a window.

Roughly, the program will behave like this:
1. User left-clicks folder A on the desktop.
2. Program captures the click, changes the appropriate registry keys, and refreshes the desktop view so that folder A's contents are now displayed on the desktop. (Folder A does not open in an explorer window).

I'm competent at programming, but don't have much experience with the Windows API or hooking. From some googling, I gather that a decent approach is to hook WH_MOUSE_LL, but it seems that detecting whether the clicked object is a folder is non-trivial and potentially kludgey.

Can you advise a general approach that (1) accomplishes the described behavior and (2) isn't too hacky?

Thanks so much,
posted by long to Computers & Internet (12 answers total) 1 user marked this as a favorite
Ugly hack: make a large Active Desktop page in the middle of the desktop and use the IE integration with explorer.

I know nothing about the Windows API.
posted by katrielalex at 2:46 PM on June 27, 2009

Is there a reason this needs to be a mouse detection trick and that a program that you run wouldn't suffice? Because it wouldn't be too difficult to code something up in AutoIT that would make the changes you need and then compile it as an executable you can run at will.
posted by JaredSeth at 2:54 PM on June 27, 2009

@ JaredSeth: I basically want Windows Explorer embedded in my desktop. As far as I can tell, AutoIT only does mouse manipulation, not detection, so it won't work for me.
posted by long at 3:07 PM on June 27, 2009

I doubt this would work. You might have to kill and restart explorer to refresh your registry key change.
posted by wongcorgi at 3:08 PM on June 27, 2009

long, I guess that's what I was wondering is why the need for integration? Heck, to get around the necessary explorer refresh that wongcorgi is referring to, you could easily script something that just moves the contents of your Desktop to that folder and vice versa.
posted by JaredSeth at 3:16 PM on June 27, 2009

Ugly hack: You could create a bunch of shortcuts to every item in the folder when you double click a folder, or shortcut to folder. And then delete them

But why would you want to do this? What would happen when there are more files then you have space for on the desktop?
posted by delmoi at 3:17 PM on June 27, 2009

Not integration, detection I mean. In other words, is there a reason it needs to work the way you're envisioning when you could make an executable that achieves the same effect?
posted by JaredSeth at 3:19 PM on June 27, 2009

@ wongcorgi: This works. If you change the Desktop location registry keys manually (or with, say, TweakUI), all you have to do for the desktop to refresh is right click the desktop and click refresh.

@ responders in general: I think there's some confusion as to what this program is - it implements a dynamic desktop metaphor. I know it's possible from a programming standpoint, I just want some advice on the cleanest approach. If you haven't heard of the term "desktop metaphor" and you don't know anything about the Windows API, don't bother answering.
posted by long at 3:29 PM on June 27, 2009

long, just trying to understand why it needs to be on a mouseclick event.

You could write a vbscript that rewrites the reg keys and uses SendKeys to run a refresh of the desktop. Add it as a shell command for folders (named Switch Desktops for example) and you could right click on the folder and select Switch Desktops.

But really if you want a "dynamic desktop metaphor", why not just use a virtual desktop manager?
posted by JaredSeth at 4:10 PM on June 27, 2009

Heck, now that I think about it, that vbscript could be pretty cool, especially because it would work with any folder. I may have to code that up for myself.
posted by JaredSeth at 4:13 PM on June 27, 2009

Have you considered asking this question at Stack Overflow?

That said, I'd be shocked if there wasn't an easier, higher-level way of getting a "Folder Opened" notification from Explorer besides hooking the mouse events API (and then what? Hit-testing?). Have you looked at IExplorerBrowserEvents? I don't know if there will be any way to filter non-Desktop browses from that though.

Also, side-note, my experience with trying to do this kind of stuff on Windows is that its a huge PITA if you want it to work on a wide variety of systems. If you are just making a util for yourself, no big, but debugging things that interact with the Windows Shell is insane.
posted by jeb at 4:16 PM on June 27, 2009

A very ghetto way - enable auditing on your folders to capture opening of folders via GPO and monitor the event log for new Success Audit entries.
posted by wongcorgi at 5:50 PM on June 27, 2009

« Older Upcoming nonfiction review sites?   |   Tell me about competitive music Newer »
This thread is closed to new comments.