Click here to Skip to main content
15,898,926 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Solving a repaint problem in VS2005 Pin
theCPkid23-Oct-09 19:00
theCPkid23-Oct-09 19:00 
GeneralRe: Solving a repaint problem in VS2005 Pin
SimplCodr24-Oct-09 5:12
SimplCodr24-Oct-09 5:12 
QuestionConvert BYTE* array (unmanaged) to SAFEARRAY Pin
TalSt22-Oct-09 6:13
TalSt22-Oct-09 6:13 
QuestionRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
CPallini22-Oct-09 8:20
mveCPallini22-Oct-09 8:20 
AnswerRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
Randor 22-Oct-09 16:13
professional Randor 22-Oct-09 16:13 
GeneralRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
TalSt24-Oct-09 19:50
TalSt24-Oct-09 19:50 
GeneralRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
Randor 26-Oct-09 9:59
professional Randor 26-Oct-09 9:59 
QuestionHow to read the characters in the EditTable of SysListView32 style control ? Pin
wangningyu22-Oct-09 5:41
wangningyu22-Oct-09 5:41 
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();
	......

	// TODO: Add extra initialization here
	// Set the ListCtrl style
	LONG lStyle = m_ListCtrl.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
	lStyle |=  LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
	m_ListCtrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0,(LPARAM)lStyle);


	// Add ListCtrl titles
	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;  // return TRUE  unless you set the focus to a control
}
void CTestDlg::OnBtnRead() 
{
	// TODO: Add your control notification handler code here
	m_ListCtrl.DeleteAllItems();


	// Find window handle
	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;


	// Get the ListView lines.
	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);


	// Get process 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);
	_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;


	// Here use degression , order with the task manager
	for(i=count; i>=0; i--)
	{
		// Read first item data
		lvi.iSubItem=0;
		lvi.pszText=_firstitem;
		WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
		::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);


		// Read second item data
		lvi.iSubItem=1;
		lvi.pszText=_secitem;
		WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
		::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);


		// Read 3rd item data
		lvi.iSubItem=2;
		lvi.pszText=_thirditem;
		WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
		::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);


		// Read fourth item data
		lvi.iSubItem=3;
		lvi.pszText=_fourthitem;
		WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
		::SendMessage(hListview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);


		// Read the process memory.
		ReadProcessMemory(process, _firstitem,	firstitem,	512, NULL);
		ReadProcessMemory(process, _secitem,	secitem,	512, NULL);
		ReadProcessMemory(process, _thirditem,	thirditem,	512, NULL);
		ReadProcessMemory(process, _fourthitem,	fourthitem,	512, NULL);


		// Format strings.
		str1.Format("%s",firstitem);
		str2.Format("%s",secitem);
		str3.Format("%s",thirditem);
		str4.Format("%s",fourthitem);


		// Add it into my ListCtrl.
		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);
	}


	// Release memory
	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 ?
QuestionRe: How to read the characters in the EditTable of SysListView32 style control ? Pin
David Crow22-Oct-09 6:23
David Crow22-Oct-09 6:23 
AnswerRe: if the edit listcontrol in other programs, how can I read the list ?[modified] Pin
wangningyu22-Oct-09 6:35
wangningyu22-Oct-09 6:35 
GeneralRe: if the edit listcontrol in other programs, how can I read the list Pin
David Crow22-Oct-09 7:08
David Crow22-Oct-09 7:08 
AnswerRe: How to read the characters in the EditTable of SysListView32 style control ? Pin
rand094122-Oct-09 15:01
rand094122-Oct-09 15:01 
AnswerRe: How to read the characters in the EditTable of SysListView32 style control ? Pin
nenfa19-Jan-10 0:21
nenfa19-Jan-10 0:21 
QuestionDeviceIoControl to lock drive is not working Pin
Patcher3222-Oct-09 5:09
Patcher3222-Oct-09 5:09 
AnswerRe: DeviceIoControl to lock drive is not working Pin
Covean22-Oct-09 5:34
Covean22-Oct-09 5:34 
GeneralRe: DeviceIoControl to lock drive is not working Pin
Patcher3222-Oct-09 13:12
Patcher3222-Oct-09 13:12 
AnswerRe: DeviceIoControl to lock drive is not working Pin
Code-o-mat22-Oct-09 5:52
Code-o-mat22-Oct-09 5:52 
GeneralRe: DeviceIoControl to lock drive is not working Pin
Patcher3222-Oct-09 13:13
Patcher3222-Oct-09 13:13 
GeneralRe: DeviceIoControl to lock drive is not working Pin
David Crow22-Oct-09 6:20
David Crow22-Oct-09 6:20 
GeneralRe: DeviceIoControl to lock drive is not working Pin
Code-o-mat22-Oct-09 6:34
Code-o-mat22-Oct-09 6:34 
GeneralRe: DeviceIoControl to lock drive is not working Pin
David Crow22-Oct-09 6:56
David Crow22-Oct-09 6:56 
AnswerRe: DeviceIoControl to lock drive is not working Pin
Patcher3222-Oct-09 13:44
Patcher3222-Oct-09 13:44 
GeneralRe: DeviceIoControl to lock drive is not working Pin
Covean22-Oct-09 20:59
Covean22-Oct-09 20:59 
GeneralRe: DeviceIoControl to lock drive is not working Pin
Patcher3223-Oct-09 19:22
Patcher3223-Oct-09 19:22 
QuestionRenaming file in C++ failing Pin
StrayGrey22-Oct-09 3:58
StrayGrey22-Oct-09 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.