views:

3607

answers:

5

Several years back, I innocently tried to write a little app to save my tactically placed desktop icons because I was sick of dragging them back to their locations when some event reset them. I gave up after buring WAY too much time having failed to find a way to query, much less save and reset, my icons' desktop position.

Anyone know where Windows persists this info and if there's an API to set them?

Thanks, Richard

+1  A: 

I have no idea about the API, but I know Ultramon (http://www.realtimesoft.com/ultramon/) has a feature included for preserving icon placement (although I've never used it for preserving icon location, it is indispensable for multiple monitor usage). The latest beta release works flawlessly with Vista (except for sometimes having a minor glitch or two when initially logging into my machine via RDP), and of course, haven't had any issues with XP. I've used it for over four years now.

And did I mention that it's the best utility for multiple monitor usage?

Ted
+2  A: 

If I'm not mistaken the desktop is just a ListView, and you'll have to send the LVM_SETITEMPOSITION message to the handle of the desktop.

I googled a bit for some c# code and couldn't find a example, but I did found the following article. Torry: ...get/set the positions of desktop icons?. It's delphi code, but I find it very readable and with some P/Invokes you'll be able to translate it to c#.

Davy Landman
I started using that code as the basis, but then while googling something from it, found the link I posted as an answer, so I'll credit you with the answer, thanks.
ZeroBugBounce
+1  A: 

The desktop is just a ListView control and you can get its handle and send messages to it to move icons around using LVM_SETITEMPOSITION.

Getting icon positions using LVMGETITEMPOS is a bit more complicated, though. You have to pass a pointer to a POINT structure as your LPARAM. If you try to do that, you will likely crash Explorer. The problem is you passed it a pointer in your address space, which the control interpreted as a pointer in Explorer's address space. Ouch!

The solution I've used is to inject a DLL into the Explorer process and send the message from there. Then you just have to have a way to get the position info back to your process.

Ferruccio
+1  A: 

I am still looking into this and will post the result once I finally get something working. I'm posting this because, thanks indirectly to Davy's post, I also found a classic VB implementation:

http://www.freevbcode.com/ShowCode.ASP?SearchString=desktop%20shuffle&ID=3290

and that will probably be the basis for my code.

ZeroBugBounce
A: 

It's a Usenet FAQ You can ask on specialized Win32 api newsgroup : news://194.177.96.26/comp.os.ms-windows.programmer.win32 where it has often been discussed