用如下代表给其它程序的列表框增加了两行数据, 已经可以了,但是一个新的问题是, 这个列表框上的数据不会消息了,每次都是从累加的增加. 为什么 ?
if ( !::IsWindow(listview) )
return;
TRACE("AddItemToList");
DWORD dwStyle = ::SendMessage(listview, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
LVITEM lvi, *_lvi;
lvi.cchTextMax=512;
char *_item;
unsigned long pid;
HANDLE process;
GetWindowThreadProcessId(listview, &pid);
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
//申请远程内存,获得_lvi 和 _item 的远程地址
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM),
MEM_COMMIT, PAGE_READWRITE);
_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);
//插入一项提示现在处于搜索模式
lvi.mask = LVIF_TEXT; //标志位 文本
lvi.iItem = 0 ; //可修改为想要插入的行
lvi.iSubItem = 0; //此项是第几列的数据
lvi.pszText =_item; //文本
WriteProcessMemory(process, _item, _T("test item"), 512, NULL);
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(listview, LVM_INSERTITEM, 0,(LPARAM)_lvi);
lvi.mask = LVIF_TEXT;
lvi.iItem = 0 ; //可修改为想要插入的行
lvi.iSubItem = 1;
lvi.pszText = _item;
WriteProcessMemory(process, _item, _T("bbbbb"), 512, NULL);
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(listview,LVM_SETITEM,0,(LPARAM)_lvi);
::SendMessage(listview, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
CloseHandle (process);
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课