Getting activation events from listview control

Sorry if this has been asked before but i have been struggling for some time over this.

I am trying to get the lParam value of an element in a list-view control when it is activated
case WM_NOTIFY: {
switch (((LPNMHDR)lParam)->code) {
printf("%d %ld
", lpNMItem->iItem, lpNMItem->lParam);
} break;
} break;
} break;

output is always " 2292592", where index is correct, but lParam is always 2292592.

lParam values must be being added because the following always returns the expected value.

to find items (this works)
LVFINDINFO find_info = {
.flags = LVFI_PARAM,
.lParam = id,
return ListView_FindItem(g_list_view_control, -1, &find_info);

to insert item (this works)
LV_ITEM pItem = {
ListView_InsertItem(g_list_view_control, &pItem);


  • [color=Blue]It is always nice to see what Microsoft i saying about their API:


    There are few things about this:
    1. lParam is not always pointing to same information (see version remark)
    2. Some other message have to be used AFTER getting that notification
    3. If you go by [u]NMITEMACTIVATE[/u] link you will see that lParam inside it is not always set - there is some remark on "not all notifications using it"

    In any event, my advice is to use LVM_GETSELECTEDCOUNT and LVM_GETNEXTITEM to get indexes of selected rows and then use LVM_GETITEM to get the data (LPARAM) attached to each row. In my experience the information contained in WM_NOTIFY lParam part is not always proper and it is better to use additional messages to a control to get data you need. This way your code is ensured to work on all Windows versions.
  • Thanks, using ListView_GetItem worked perfectly.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!