设置另一个程序的列表视图所选项目
我希望能够选择在另一个程序的列表视图中选择哪个项目(我无权访问其代码)。 实际上,它是一个 SysListView32,我认为它是相同的。 我已经有了下面的代码,不幸的是,尽管编译了,但它似乎什么也没做(尽管 SendMessage() 返回 1)。
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, 0xD14);
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
lvi.state = LVIS_SELECTED | LVIS_FOCUSED;
lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
int abc = ::SendMessage((HWND)0x00050D30, LVM_SETITEMSTATE, (WPARAM)2, (LPARAM)_lvi);
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
I want to be able to select which item is selected in another program's list view(I don't have access to its code). Actually, it is an SysListView32, which I assume is the same. I already have the following code, which unfortunely despite compiling, seems to do nothing (although SendMessage() returns 1).
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, 0xD14);
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
lvi.state = LVIS_SELECTED | LVIS_FOCUSED;
lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
int abc = ::SendMessage((HWND)0x00050D30, LVM_SETITEMSTATE, (WPARAM)2, (LPARAM)_lvi);
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下代码对我来说就像一个魅力:
您的代码可能无法工作有多种原因:
MEM_COMMIT
内存,然后MEM_RELEASE
(这与MEM_RESERVE
相反);如果所有这些都不起作用,我建议尝试不同的方法: IAccessible 在这里可能会有所帮助。 这里通常的免责声明:弄乱其他进程窗口和地址空间需要谨慎的方法,并且应该尽可能避免。
The following code works like a charm for me:
There are several reasons why your code might not work:
MEM_COMMIT
the memory, but thenMEM_RELEASE
's it (which is opposite toMEM_RESERVE
);If all that doesn't work, I'd recommend trying a different approach: IAccessible might be helpful here. Usual disclaimers here: messing with other processes windows and address space requires careful approach and should be avoided if possible.
如何初始化正在复制到目标进程内存中的源 LV_ITEM 的其余成员? 您是否在源 LV_ITEM 的“掩码”成员中包含 LVIF_STATE 标志? 如果不是,那么 ListView 将忽略您尝试指定的“state”和“stateMask”值。
How are you initializing the rest of the members of the source LV_ITEM that is being copyied into the target process's memory? Are you including the LVIF_STATE flag in the source LV_ITEM's "mask" member? If not, then the ListView will ignore the "state" and "stateMask" values that you are trying to specify.
如果您遇到困难,有一个名为 AutoHotKey 的开源项目,它可以创建可以轻松选择列表中的项目等的脚本。
If you get stuck, there is an open source project called AutoHotKey that can create scripts that can easily select items in lists, etc.
您必须在提交内存之前保留地址空间。 您可以通过将
MEM_COMMIT
更改为MEM_RESERVE|MEM_COMMIT
来同时执行这两项操作You have to reserve address space before committing memory. You can do both at once by changing
MEM_COMMIT
toMEM_RESERVE|MEM_COMMIT