I have a program with a CListCtrl, Style REPORT, OWNER_DRAW and OWNER_DATA. I do not know the code. I have to download any new item in this list for my program (each consists of 3 subitems).
Speed is required reading list and insert this into my program, each new item appears on the position 0.
I find the handle controls and do this:
* Counting elements
int getItemCount(HWND mHwnd)
{
return((int)SendMessage(mHwnd, LVM_GETITEMCOUNT, 0, 0));
}
* I do read the item so
LPSTR getItem(HWND listview, int nItem, int nType)
{
int i;
LVITEM lvi, *_lvi;
char item[512], subitem[512];
char *_item, *_subitem;
unsigned long pid;
HANDLE process;
LPSTR lps="";
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);
_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,PAGE_READWRITE);
_subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,PAGE_READWRITE);
lvi.cchTextMax=512;
i=nItem;
if(nType==0)
{
lvi.iSubItem=0;
lvi.pszText=_item;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
ReadProcessMemory(process, _item, item, 512, NULL);
lps=item;
}
if(nType==1)
{
lvi.iSubItem=1;
lvi.pszText=_subitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
ReadProcessMemory(process, _subitem, subitem, 512, NULL);
lps=subitem;
}
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);
free(_lvi);
free(_item);
free(_subitem);
return(lps);
}
everything would be beautiful if not for the fact that the reading list I have to do in quite a stupid way, namely in the loop while (hwnd! = NULL) ....
unnecessarily burden the CPU and it is quite inefficient way temporarily, I lose 300 to 600 ms because in the loop as the last elements are compared to verify whether entered something new or not and how many items entered.
New items come in quantities of 1 to 10 and more at the moment at an unspecified time. Programm continuously detects whether it is something new.
How to capture the event that an external application notifying the new item ????
Probably LVN_ITEMNOTIFY ????
Thanks for your help!