Maybe I have this all completely wrong because I don't know what I'm doing, but I'm trying to work with win32 programming and I want to get the position of all the items on the desktop.

I've found the handle for the desktop and I've found the LVM constants in commctrl.py
But I really have no idea what I'm doing.

import commctrl
import win32gui

print win32gui.SendMessage(1310822,commctrl.LVM_GETITEMPOSITION)

Unfortunately this only returns 0. I don't know what I'm doing and all I can find online is instructions for how to do this in other programming languages, which I don't understand.

Maybe I have this all completely wrong because I don't know what I'm doing, but I'm trying to work with win32 programming and I want to get the position of all the items on the desktop.

I've found the handle for the desktop and I've found the LVM constants in commctrl.py
But I really have no idea what I'm doing.

import commctrl
import win32gui

print win32gui.SendMessage(1310822,commctrl.LVM_GETITEMPOSITION)

Unfortunately this only returns 0. I don't know what I'm doing and all I can find online is instructions for how to do this in other programming languages, which I don't understand.

I don't know much on win32 but I know there is python module for that by Mark hammond and here is the link. Just install and try to locate pywin help file and I guess it will guide you.

http://sourceforge.net/projects/pywin32/

I have a feeling he's already using that module. Look at the imports.

Yes, I am already using the win32 package and unfortunately the documentation is not optimal. For a person who is not familiar with many of the terms and phrases used, the documentation is often very hard to understand and apply to projects.

And unfortunately information about this that can be found on the internet isn't much better on shedding light on the confusion. That is why I came here hoping that there is somebody that actually knows how to do this and is willing to share their knowledge.

Okay, I've figured out that using commctrl.LVM_GETITEMCOUNT returns the number of icons on the desktop, so I'm doing something right here. Maybe commctrl.LVM_GETITEMPOSITION just isn't a valid message for this type of handle.

I will take a look at those links and see if I can learn something. I already know a little bit about pywin stuff, but I would like to learn more.

Anyway, if anyone knows how to return the position of icons on the desktop, please let me know.

http://msdn.microsoft.com/en-us/library/bb761048(VS.85).aspx
That's the documentation for the LVM_GETITEMPOSITION message in the win32 api. In my understanding, a call should look like this:

hwnd = # Somehow get the handle to the listview
index = # This is the index of the item in the listview. Since you already have the number of items from LVM_GETITEMCOUNT, it shouldn't be hard figuring out which indices to use.
point = # This is a win32 point structure which i'm pretty sure pywin32 implements.

SendMessage(hwnd, LVM_GETITEMPOSITION, UINT(index), point)

#point should now contain the position.

So, if the code above is the correct way, all you need to do is find out how to get the desktop list view control handle, and how to get a point structure in pywin32.

I found some information here- http://www.3dconnexion.com/forum/viewtopic.php?=&p=5732

So now I can do:

from win32gui import *
from commctrl import *
from ctypes import *

desk=524424 # The handle to the desktop

class POINT(Structure):
     '''I think this is the way to set up the point structure'''
     _fields_=[('x', c_long),('y', c_long)]

SendMessage(desk, LVM_SETITEMPOSITION, 0, POINT(400,400))

'''I thought this was supposed to move the icon at position 0 to the point (400,400). Actually all it does is make the icon disappear. This is with auto arrange and align icons turned off. Anybody know what the problem is?'''
'''And this crashes explorer just like in what I\'ve read about other attempts to use LVM_GETITEMPOSITION using other languages.'''

SendMessage(desk, LVM_GETITEMPOSITION, 0, POINT())

'''I don\'t know how to fix this. Does anybody?'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.