[python-win32] python-win32 Digest, Vol 92, Issue 16

admin at genesisware.de admin at genesisware.de
Sat Nov 20 12:57:50 CET 2010


Thanks for you answer. The handle is unfortunately from another process.

This is a piece of code I have found on the web that works great to get the values of a list from another process. I have marked the part where I want to select a list item:

def readListViewItems(hwnd, column_index=0):

	# Allocate virtual memory inside target process
	pid = ctypes.create_string_buffer(4)
	p_pid = ctypes.addressof(pid)
	GetWindowThreadProcessId(hwnd, p_pid) # process owning the given hwnd
	hProcHnd = OpenProcess(PROCESS_ALL_ACCESS, False, struct.unpack("i",pid)[0])
	pLVI = VirtualAllocEx(hProcHnd, 0, 4096, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE)
	pBuffer = VirtualAllocEx(hProcHnd, 0, 4096, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE)

	# Prepare an LVITEM record and write it to target process memory
	lvitem_str = struct.pack('iiiiiiiii', *[0,0,column_index,0,0,pBuffer,4096,0,0])
	lvitem_buffer = ctypes.create_string_buffer(lvitem_str)
	copied = ctypes.create_string_buffer(4)
	p_copied = ctypes.addressof(copied)
	WriteProcessMemory(hProcHnd, pLVI, ctypes.addressof(lvitem_buffer), ctypes.sizeof(lvitem_buffer), p_copied)

	# iterate items in the SysListView32 control
	num_items = win32gui.SendMessage(hwnd, LVM_GETITEMCOUNT)
	item_texts = []
	for item_index in range(num_items):
		win32gui.SendMessage(hwnd, LVM_GETITEMTEXT, item_index, pLVI)
		target_buff = ctypes.create_string_buffer(4096)
		ReadProcessMemory(hProcHnd, pBuffer, ctypes.addressof(target_buff), 4096, p_copied)
		item_texts.append(target_buff.value)
		
		if target_buff.value == "something":
			# HERE THE list item should be selected, if the value of the list item is something
			#
			#
			#
			pass

	VirtualFreeEx(hProcHnd, pBuffer, 0, MEM_RELEASE)
	VirtualFreeEx(hProcHnd, pLVI, 0, MEM_RELEASE)
	win32api.CloseHandle(hProcHnd)
	return item_texts

Do you have an idea?

-----Ursprüngliche Nachricht-----
Von: python-win32-bounces+admin=genesisware.de at python.org [mailto:python-win32-bounces+admin=genesisware.de at python.org] Im Auftrag von python-win32-request at python.org
Gesendet: Samstag, 20. November 2010 12:00
An: python-win32 at python.org
Betreff: python-win32 Digest, Vol 92, Issue 16

Send python-win32 mailing list submissions to
	python-win32 at python.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.python.org/mailman/listinfo/python-win32
or, via email, send a message with subject or body 'help' to
	python-win32-request at python.org

You can reach the person managing the list at
	python-win32-owner at python.org

When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..."


Today's Topics:

   1. Re: Simple selection of item in list (Tim Roberts)


----------------------------------------------------------------------

Message: 1
Date: Fri, 19 Nov 2010 10:43:38 -0800
From: Tim Roberts <timr at probo.com>
To: Python-Win32 List <python-win32 at python.org>
Subject: Re: [python-win32] Simple selection of item in list
Message-ID: <4CE6C55A.806 at probo.com>
Content-Type: text/plain; charset="UTF-8"

admin at genesisware.de wrote:
> my problem is probably simple but I haven?t found a solution anyway. I want so select items from an item list that allows multiple selections.
>
> I have got the handle of a SysListView32 control and the item index of the item I want to select.
>
> How can I arrange this in pywin?

Where did the handle come from?  Is this a control within your own application?  One of the awkward things about the SysListView32 control is that most of its messages require structures, and the structures are not marshaled properly across process boundaries, so it's very difficult to control one in another process.

If it is within your own process, you can send an LVM_SETITEMSTATE message with the appropriate LVITEM structure.

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



------------------------------

_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32


End of python-win32 Digest, Vol 92, Issue 16
********************************************






More information about the python-win32 mailing list