我有一个带有ListView('SysListView32')控件的应用程序,我想从中提取数据。控件有4列,只有文本数据。在
我一直在玩下面的台词(在网上找到的):
VALUE_LENGTH = 256
bufferlength_int=struct.pack('i', VALUE_LENGTH)
count = win32gui.SendMessage(TargetHwnd, commctrl.LVM_GETITEMCOUNT, 0, 0)
for ItemIndex in range(count):
valuebuffer = array.array('c',bufferlength_int + " " * (VALUE_LENGTH - len(bufferlength_int)))
ListItems = win32gui.SendMessage(TargetHwnd, commctrl.LVM_GETITEMTEXT, ItemIndex, valuebuffer)
[上面的代码可能不是完全可执行的,因为我把它从无关的东西中剥离出来。但要点当然在这里。]
这似乎运行正常,但我一定是做错了什么-我得到了各种各样的数据缓冲区,大部分都是零,而没有一个真正的文本内容,我正在寻找。在
有什么建议吗?在
谢谢,
约纳坦
好吧,结果我在几点上都错了。但是,可以通过在目标进程内部分配内存,在那里构造所需的结构(LVITEM),发送消息并从所述进程中分配的缓冲区读回结果来实现。在
为了完整起见,我附加了一个代码示例,用于从外部进程读取SysListView32项,并给出了该控件的一个窗口句柄。在
如果控件与代码处于同一进程中,则它应该可以工作。如果它是在另一个过程中(正如“另一个应用程序”所建议的那样),那么这是行不通的(或者至少不应该这样)。检查一下错误代码,你应该得到一些类似于“权限被拒绝”的信息:应用程序无法看到彼此的内存。在
相关问题 更多 >
编程相关推荐