tags:

views:

566

answers:

2

Just wondering what the difference between MFC control messages prefixed with the following is:

LVN (e.g. LVN_ITEMCHANGED)
HDN (e.g. HDN_TRACK)
NM (e.g. NM_HOVER)

Also, I am using a ListControl and trapping when the user clicks on an item using the NM_CLICK message. I also want to trap when a user selects a new item view a key e.g. up/down arrow keys. Can anyone tell me which message I should be trapping for this?

Thanks

+3  A: 
  • LVN = ListView Notification
  • HDN = HeaDer control Notification
  • NM = er..um.. "Notification for Mouse" ?
James Curran
NM_ are generic control notifications that are not control type specific. I parse it usually as "Notification Message".
peterchen
+1  A: 

For change in selection, you need to handle the LVN_ITEMCHANGED notification:

NMLISTVIEW & nm = *(NMLISTVIEW *) pnmh;
if (  (nm.uNewState ^ nm.uOldState) & LVIS_SELECTED) 
{     
   // nm.iItem was selected or deselected
   if (!m_internalUIChange)
   {
      // see below
   }
}

The first "if" checks if the "selected" state has changed. Note that, when selecting a different item in the list, this still fires twice: once for the old item to be deselected, and once for the new item to be selected. This is necessary, however, to fetch a "complete deselect".

This notification fires very often - even when you modify the control programmatically. If your handler should react only to user events, you will need at least a flag that you set durign these operations (I use a class together with a RAII-Lock for that, so I don't forget to reset it)

peterchen
Fantastic answer - thanks! :)
Konrad