开发者

How do I find a item in ListView control?

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 appli开发者_JAVA技巧cation.

Can some one point me in a right direction ?

Thanks.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜