Override CListCtrl::OnNotify as follows :
BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT*pResult)
{
HD_NOTIFY *pHD = (HD_NOTIFY*)lParam;
if ((pHD->hdr.code == HDN_ITEMCHANGINGA || pHD->hdr.code == HDN_ITEMCHANGINGW) && (GetStyle() & LVS_TYPEMASK) == LVS_REPORT)
{ // Invalidate empty bottom part of control to force erase the previous position of column
int nBottom,nLastItem=GetItemCount()-1;
if (nLastItem<0)
nBottom=0; // List is empty : invalidate whole client rect
else
{ // Get Y position of bottom of list (last item)
RECT ItemRect;
GetItemRect(nLastItem,&ItemRect,LVIR_BOUNDS);
nBottom=ItemRect.bottom;
}
RECT rect;
GetClientRect(&rect);
if (nBottom<rect.bottom)
{ // Set top of rect as bottom of list (last item) : rect = empty part of list
rect.top=nBottom;
InvalidateRect(&rect);
}
// NB: We must to on with default processing.
}
*pResult = 0;
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
Simply adding a HDN_ITEMCHANGING or HDN_TRACK handler with
ClassWizarddoesn’t work. These handlers are not called. Why ???
I noticed that class wizard places an ON_NOTIFY_REFLECT(…) entry for
these notifications. I’d rather put an ON_NOTIFY(…) since the
notification comes from the header control to its parent (the listctrl).
But Spy++ shows that the CtrlID of the header is 0. repplacing the
ON_NOTIFY_REFLECT entry by ON_NOTIFY(HDN_xxx,0,f) didn’t solve the
problem. That’s why I chose to override OnNotify()