You get listview control there as argument, then you need to find header from there yourself: hit testing and/or comparing coordinates:
CListCtrl* pLC = (CListCtrl*) GetDlgItem(IDC_LIST1);
CHeaderCtrl* pHC = pLC->GetHeaderCtrl();
if (pWnd->GetSafeHwnd() == pLC->GetSafeHwnd()) // <<--- Not pHC!
{
UINT nFlags = 0;
pLC->HitTest(point, &nFlags);
if(nFlags & LVHT_NOWHERE) // <<--- Header hits "nowhere"
{
CRect Position;
pHC->GetWindowRect(Position);
if(Position.PtInRect(point)) // <<--- point check
{
CMenu menu;
VERIFY(menu.LoadMenu(IDR_HEADERMENU));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = pHC;
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner);
}
}
}