I'm trying to read the text of desktop icons using win32gui (I must use win32 because I also need to get the positions of the icons and they should match the text).
I used the code in here: Use Python to extract ListView items from another application and it returned a list with empty strings. I tried to check return codes and other values and they all make sense.
If the control is in the same process as your code, it should work. If it's in a different process (as "another application" suggests), then this doesn't work (or at least it shouldn't). Check the error codes, you should get something along the lines of "permission denied".
But the desktop is in a different process and I got no error codes!
To get the handle of the desktop window I used the get_desktop()
function that I posted in the solution section in here: How to get desktop item count in python?
Any ideas? Thanks!
I found the answer! It was the LVITEM
struct that was wrong.
The struct I used was for 32 bit architecture but my computer is 64 bit (the python is 32 bit but it doesn't matter).
This forum has the assembly answer. And here is a follow up question which contains the struct in python.
Basically, the stateMask
field has to be 64 bits long and all the pointers should also be 64 bits long (pszText
, puColumns
and piColFmt
) and also lParam
. I don't understand the why stateMask
should be 64 bit yet, but that's what the follow up question is for.