void CList_getDlg::OnBUTTONgetdata()
{
// TODO: Add your control notification handler code here
m_list_cmddatas.ResetContent();
int item =m_combo_items.GetCurSel();
HWND hListview = (HWND)m_combo_items.GetItemData(item);
if(hListview==0){
AfxMessageBox("itemdata error");
return;
}
int count = (int)ListView_GetItemCount(hListview);
HWND hListviewHdr = ListView_GetHeader(hListview);
int ncols = (int)Header_GetItemCount(hListviewHdr);
int i,nItem;
// 获取ListView行数
CString strTemp;
CString str1="";
CString str2="";
CString str3="";
CString str4="";
DWORD pid;
HANDLE process;
LVITEM lvi, *_lvi;
char firstitem[512], fifthitem[512];
char *_firstitem ,*_fifthitem;
memset(firstitem,0,512);
memset(fifthitem,0,512);
// 获取窗口PID、打开进程
GetWindowThreadProcessId(hListview, &pid);
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|
PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
// 申请内存空间
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM),MEM_COMMIT, PAGE_READWRITE);
_firstitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,PAGE_READWRITE);
_fifthitem =(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,PAGE_READWRITE);
lvi.cchTextMax=512;
int col_will_read = GetDlgItemInt(IDC_EDITcolumntoread);
if((col_will_read>=ncols)||(col_will_read<0)){
AfxMessageBox("para error");
return ;
}
// 这里应该递减、保持与任务管理器一样顺序
for(i=count; i>=0; i--)
{
// 获取第一列记录
lvi.iSubItem=col_will_read;
lvi.pszText=_firstitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
// 获取第二列记录
// lvi.iSubItem=4;
// lvi.pszText=_fifthitem;
// WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
// ::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
// 读取进程内存
ReadProcessMemory(process, _firstitem, firstitem, 512, NULL);
// ReadProcessMemory(process, _fifthitem, fifthitem, 512, NULL);
// 格式化字符串
str1.Format("%s",firstitem);
// 增加到列表
if(strlen(str1))
m_list_cmddatas.AddString(str1);
}
// 释放内存空间
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _firstitem, 0, MEM_RELEASE);
// VirtualFreeEx(process, _fifthitem, 0, MEM_RELEASE);
}