Help selecting listview item

Joined
Jun 30, 2005
Messages
59
Reaction score
0
I am using this code to select a listview item. i specify the postion of item using (WPARAM)2 . So this one supposed to highlight and selct the postion 2 in the listview. But unfortuently it does not select but it does deselct. I mean if the item is selected by mouse click it can deselect it but can not select it. Could any one tell me what i am doing wrong here.Thanks


SendMessage(listview, LVM_SETITEMSTATE, (WPARAM)2, (LPARAM)_lvi);
Code:
void CSelectuserDlg::OnButton1() 
{
 // TODO: Add your control notification handler code here

 HWND listview=NULL;  // List View identifier 
 HWND parent,child; 
 parent=NULL; 
 child=NULL; 
 parent = ::FindWindow("My Window Class",NULL); 

 child =::FindWindowEx(parent,0,"WTL_SplitterWindow",NULL); 
 child =::FindWindowEx(child,0,"WTL_SplitterWindow",NULL); 
 child =::FindWindowEx(child,0,"WTL_SplitterWindow",NULL); 
 child =::FindWindowEx(child,0,"ATL:0053C8D0",NULL); 
 listview=::FindWindowEx(child,0,"SysListView32",NULL); 

 LVITEM lvi, *_lvi; 
 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=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); 
 lvi.mask = LVIF_STATE; 
 lvi.state = true; 
 lvi.stateMask = LVIS_SELECTED; 

 WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL); 
 ::SendMessage(listview, LVM_SETITEMSTATE, (WPARAM)2, (LPARAM)_lvi); 
 VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
 
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top