See the description of the
NM\_CLICK (list view) notification code | Microsoft Docs[
^]:
Quote:
The iItem member of lParam is only valid if the icon or first-column label has been clicked. To determine which item is selected when a click takes place elsewhere in a row, send an LVM_SUBITEMHITTEST message.
Add this to your code (untested):
if (t < 0)
{
LVHITTESTINFO tHitTest;
tHitTest.pt = pNMItemActivate->ptAction;
t = SendMessage(LVM_SUBITEMHITTEST, 0, reinterpret_cast<LPARAM>(&tHitTest));
}