Determining position of desktop icons

I want to write a screen saver that moves icons, windows etc that are currently on or open on the desktop.  I can determine the position of any window open, but am not sure how to get the position of icons on the desktop.  

Does anyone now how to get a hold of the positions of the icons on the desktop.
Who is Participating?
MikeP090797Connect With a Mentor Commented:
First try and make sure it's working
The Icons are part of the desktop program, not part of the OS, so there is no API for handling them.  However there is a OLE interface to the desktop manager called IShellLink.  You might look into that.
Check the following registry entries

    Explorer\Streams, and

Then look into IShellBrowser::GetViewStateStream().

Also, do a search for Q171002,
    How Windows Stores View Preferences
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

patel4694Author Commented:
I too had found the registry entries, but how does one actually parse the binary. I do not see how ShellBrowser::GetViewStateStream() would help if I have no means of parsing the stream.

I tried to look for:

>Also, do a search for Q171002,
>   How Windows Stores View Preferences

but I did not find it on MSDN(I'm assumming that is where you meant)  I also tried to look for that question on experts exchange but there are too many question to actually browse through.

Any more suggestions.  If you have sample code or attachements you would like to send me, please send to

Have a look at the online help of 'IShellFolder' in your Devstudio :) There you
can access all information you need. The Desktop is of course
just a simple IShellFolder too, accessed by SHGetDesktopFolder

patel4694Author Commented:
looks like this IShellFolder will only help in returning all info but the pysicall location of an items in the folder.

I want the CRect in screen cordinates of the area being occupied by an icon on the desktop. Sorry, but I don not see a way to get to that info using the IShellFolder.


Well, enuerate the items, then go via GetDesktopWindow
and GetRect of the items ... didn't try yet, should work

I assume that u r talking about screen saver that looks something like those done by LizardWork Inc. As far as I know, there is only 1 way to do this. That is to write a hook program in a dll and then inject this hook into the desktop instance using SetWindowsHookEx.
patel4694Author Commented:
To connex,

I'm confused.  How do you get the rect of the item from the DesktopWindowHandle when all you have is the item(which is not even a window).

Please elaborate more.
Call GetDektopWindow to get the handle of the desktop. Sicnce the desktop is a listview based window, it's supposed to respond to listview messages. Use SendMessage LVM_GETITEMPOSITION to get the item pos
Tell me how it goes
patel4694Author Commented:
Mike, please respond to this question as an answer and not a comment(since that is the only way I can give you the points)

Meanwhile, I will try your suggestion, which make great sense.  I guess the key to this question was knowing that the Desktop was a CListView derived object.

Hi all,
As I've mentioned before, using hook is the only way out. I've tried before using the way MikeP mentioned but it could not work out. May be I did it wrongly, please keep me update with the progress as i'm also interested in this issue. Why this way fails is because Desktop is in a protected process. As u try to retrieve info from it, your explorer will generate a GP fault. Don't believe, u try. This is logical as every process in Win32 is protected. I could only set the icons positions but unable to retrieve them. At least this could not be done without using hook. If anyone know of a way, please let me know. Thanks!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.