Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted

1 solution

You must install an hook procedure using the SetWindowsHookEx and the WH_SYSMSGFILTER hook type.

This way, the system calls your hook procedure before sending any message to any message loop of all the applications running on the same desktop where your thread is running: is your responsibility to filter only the messages of your interest.

Be careful in using the SetWindowsHookEx function, because you can cause serious problems; I strongly recommend you to carefully read all the related documentation on the MSDN.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900