Howdy, Stranger!

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

Categories

Getting activation events from listview control

rowdy2rowdy2 Member Posts: 2
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
[code]
case WM_NOTIFY: {
switch (((LPNMHDR)lParam)->code) {
case LVN_ITEMACTIVATE: {
LPNMITEMACTIVATE lpNMItem = (LPNMITEMACTIVATE)lParam;
printf("%d %ld
", lpNMItem->iItem, lpNMItem->lParam);
} break;
} break;
} break;
[/code]

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)
[code]
LVFINDINFO find_info = {
.flags = LVFI_PARAM,
.lParam = id,
};
return ListView_FindItem(g_list_view_control, -1, &find_info);
[/code]

to insert item (this works)
[code]
LV_ITEM pItem = {
.mask = LVIF_TEXT | LVIF_PARAM,
.pszText=s->title,
.lParam=s->id,
};
ListView_InsertItem(g_list_view_control, &pItem);
[/code]

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [color=Blue]It is always nice to see what Microsoft i saying about their API:

    [link=http://msdn.microsoft.com/en-us/library/bb774843(VS.85).aspx]http://msdn.microsoft.com/en-us/library/bb774843(VS.85).aspx[/link]

    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.
    [/color]
  • rowdy2rowdy2 Member Posts: 2
    Thanks, using ListView_GetItem worked perfectly.
Sign In or Register to comment.