用python怎么查看syslistview32的内容
如题
用c++的话,SendMessage(hwnd, LVM_GETITEMTEXT, i, (LPARAM)plvitem)可以获得,但是(LPARAM)plvitem这个在python里面怎么获取?
谢谢~
[最优解释]
参考一下Notepad的
# encoding: cp936
import win32gui,win32api,win32con
def MsgBox(text, title="Python"):
win32api.MessageBox(0, text, title, 0)
def ShellExecute(file="", option="", dir=""):
win32api.ShellExecute(0, "open", file, option, dir, win32con.SW_SHOWNORMAL)
def SetForegroundWindow(whnd):
win32gui.SetForegroundWindow(whnd)
def FindWindow(classname=None, title=None):
whnd = win32gui.FindWindow(classname, None)
return whnd
def FindWindowEx(handle=None, classname=None):
ehnd = win32gui.FindWindowEx(handle,0,classname,None)
return ehnd
def SetText(ehnd, text):
win32gui.SendMessage(ehnd, win32con.WM_SETTEXT, 0, text)
def SetSelText(ehnd, text):
win32gui.SendMessage(ehnd, win32con.EM_REPLACESEL, 0, text)
def GetText(ehnd):
buf_size = 1 + win32gui.SendMessage(ehnd, win32con.WM_GETTEXTLENGTH, 0, 0)
buffer = win32gui.PyMakeBuffer(buf_size)
win32gui.SendMessage(ehnd, win32con.WM_GETTEXT, buf_size, buffer)
return buffer[:buf_size]
if __name__=='__main__':
whnd = FindWindow("Notepad", None)
ehnd = FindWindowEx(whnd, "Edit")
print whnd,ehnd
SetForegroundWindow(whnd)
SetText(ehnd, "xyz")
print GetText(ehnd)
from win32con import PAGE_READWRITE, MEM_COMMIT, MEM_RESERVE, MEM_RELEASE,\
PROCESS_ALL_ACCESS
from commctrl import LVM_GETITEMTEXT, LVM_GETITEMCOUNT
import struct
import ctypes
import win32api
import win32gui
GetWindowThreadProcessId = ctypes.windll.user32.GetWindowThreadProcessId
VirtualAllocEx = ctypes.windll.kernel32.VirtualAllocEx
VirtualFreeEx = ctypes.windll.kernel32.VirtualFreeEx
OpenProcess = ctypes.windll.kernel32.OpenProcess
WriteProcessMemory = ctypes.windll.kernel32.WriteProcessMemory
ReadProcessMemory = ctypes.windll.kernel32.ReadProcessMemory
memcpy = ctypes.cdll.msvcrt.memcpy
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