How do I find a item in ListView control?

给你一囗甜甜゛ 提交于 2019-12-24 00:33:36

问题


My list view contains 3 columns Name, address and phone number.

I want to retrieve an index for a particular name.

I'm using ListView_FindItem macro to find the index number but when my code comes to this line it crashes the program.

It just says Payroll has stopped working. Windows can check online for a solution to the problem.

I'm sure I have passed right handle to the ListView_FindItem macro but I'm not sure about the LVFINDINFO structure.

Here's my code

WCHAR szProcess[80] = {0};
LVFINDINFO item = {LVFI_STRING, (LPCTSTR) szProcess};

//code to find parent handles
...

//code to find index
index = ListView_FindItem(hwndListView, -1, &item);

I'm not sure about the LVFI_STRING flag and I have even tried passing a constant LVFINDINFO structure to ListView_FindItem macro still my program crashes.

Note : The above code is not part of the payroll application. I mean to say the payroll application has the listview and I'm trying to search the item from other application.

Can some one point me in a right direction ?

Thanks.


回答1:


Your description is a little unclear, but I interpret it that you are sending LVM_FINDITEM message (via the ListView_FindItem() macro) to a window in a different process.

This simply does not work for this particular Windows message since it passes a pointer to a struct in the calling process which is meaningless when interpreted in the context of the other process (the payroll app that owns the list view).

To solve your problem you could allocate memory in the other process although this is quite a complex task. A commonly cited example of the technique is to be found in the Code Project article, Stealing Program's Memory.

Perhaps a simpler approach would be to use WM_COPYDATA which will marshal string data between processes. If that doesn't have enough flexibility then you'd need to find another IPC mechanism, e.g. named pipes.



来源:https://stackoverflow.com/questions/5688927/how-do-i-find-a-item-in-listview-control

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!