Hello everyone !
Here I want to read one of the ListCtrl datas from other process(report style),and write them into my ListCtrl.
Example this code ,I want to read the "Window Task Manager" datas(in Process Tab),and write it into my ListCtrl:
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
......
LONG lStyle = m_ListCtrl.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
lStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
m_ListCtrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0,(LPARAM)lStyle);
m_ListCtrl.InsertColumn(0,"Name",NULL,100, -1);
m_ListCtrl.InsertColumn(1,"PID",NULL,60,-1);
m_ListCtrl.InsertColumn(2,"User",NULL,120,-1);
m_ListCtrl.InsertColumn(3,"CPU",NULL,60,-1);
return TRUE;
}
void CTestDlg::OnBtnRead()
{
m_ListCtrl.DeleteAllItems();
HWND hWnd,hListview;
hWnd=::FindWindow(NULL,_T("Windows Task Manager"));
hWnd=::FindWindowEx(hWnd,0,"#32770",0);
hListview=::FindWindowEx(hWnd,0,_T("SysListView32"),NULL);
if(!hListview)
{
MessageBox("Listview handle is NULL !");
return;
}
int count = (int)::SendMessage(hListview,LVM_GETITEMCOUNT,0,0);
int i,nItem;
CString strTemp;
strTemp.Format("Total process :%d",count);
MessageBox(strTemp);
CString str1="";
CString str2="";
CString str3="";
CString str4="";
DWORD pid;
HANDLE process;
LVITEM lvi, *_lvi;
char firstitem[512], secitem[512],thirditem[512],fourthitem[512];
char *_firstitem, *_secitem,*_thirditem,*_fourthitem;
memset(firstitem,0,512);
memset(secitem,0,512);
memset(thirditem,0,512);
memset(fourthitem,0,512);
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);
_secitem =(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,PAGE_READWRITE);
_thirditem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,PAGE_READWRITE);
_fourthitem=(char*)VirtualAllocEx(process,NULL, 512, MEM_COMMIT,PAGE_READWRITE);
lvi.cchTextMax=512;
for(i=count; i>=0; i--)
{
lvi.iSubItem=0;
lvi.pszText=_firstitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
lvi.iSubItem=1;
lvi.pszText=_secitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
lvi.iSubItem=2;
lvi.pszText=_thirditem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
lvi.iSubItem=3;
lvi.pszText=_fourthitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
ReadProcessMemory(process, _firstitem, firstitem, 512, NULL);
ReadProcessMemory(process, _secitem, secitem, 512, NULL);
ReadProcessMemory(process, _thirditem, thirditem, 512, NULL);
ReadProcessMemory(process, _fourthitem, fourthitem, 512, NULL);
str1.Format("%s",firstitem);
str2.Format("%s",secitem);
str3.Format("%s",thirditem);
str4.Format("%s",fourthitem);
nItem = m_ListCtrl.InsertItem(0,str1);
m_ListCtrl.SetItem(nItem,1,1,str2,NULL,0,0,0);
m_ListCtrl.SetItem(nItem,2,1,str3,NULL,0,0,0);
m_ListCtrl.SetItem(nItem,3,1,str4,NULL,0,0,0);
}
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _firstitem, 0, MEM_RELEASE);
VirtualFreeEx(process, _secitem, 0, MEM_RELEASE);
VirtualFreeEx(process, _thirditem, 0, MEM_RELEASE);
VirtualFreeEx(process, _fourthitem, 0, MEM_RELEASE);
}
but in some progrmas, when you double click one item,you can edit it as use EditBox. so I can't used the above method to read the data from the control.
How can I read them ?
|