Jason Hilton wrote: > Okay, so I am new to python win32 development and I am trying to find > the location of icons on the desktop. I understand that the desktop is > just a listview control so theoretically I should be able to use this > code- > > from commctrl import * > from win32gui import * > from ctypes import * > > class POINT(Structure): > _fields_=[('x',c_long),('y',c_long)] > > desk=1435653 # Handle to the desktop. I just made this up for the > example here. > > SendMessage(desk,LVM_GETITEMPOSITION,0,POINT()) > > I think this is supposed to return the point that the icon in index 0 > is located at, but when I try to use this, explorer crashes. I have > researched this online and found similar predicaments that other > people have had where explorer crashed using GETITEMPOSITION, but > those examples are in other programming languages that I can't read > and don't understand, and I haven't found any examples in Python on > how to overcome this problem, if indeed it is possible. > >
I assume you are getting the desktop list view handle by doing something like this: h1 = FindWindow( "progman", None ) h2 = FindWindowEx( h1, 0, "SHELLDLL_DefView", None ) h3 = FindWindowEx( h2, 0, "syslistview32", None ) There are several problems in front of you, one minor, one major. The minor problem is that the last parameter to LVM_GETITEMPOSITION needs to be a pointer to a POINT structure. In order to get information back, you'd need to pass a pointer to an existing object. pt = POINT() SendMessage( h3, LVM_GETITEMPOSITION, 0, pointer(pt) ) However, there is a much more difficult problem to solve. Remember that the desktop window is owned by a different process, and its window procedure is part of that process. With one specific exception, you can't pass pointers in a SendMessage or PostMessage call that is going to a different process. When the list view within Explorer gets your message, it thinks the address in the message is an address within its own process. It's going to overwrite some random data within Explorer. Your structure won't be touched, because Explorer can't write into your process. The solution to this is a very tricky piece of code that actually allocates a piece of memory in Explorer's process, then uses WriteProcessMemory and ReadProcessMemory to copy the data in and out. Here's the code in VB, but it's very easy to screw this up with disastrous results: http://www.vbforums.com/archive/index.php/t-546207.html -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32