coding monster
coding monster

Reputation: 394

Never notify HDN_TRACK message of CListCtrl's CHeaderCtrl

I want to catch HDN_TRACK message from listCtrl's header, but it's never notified.

I tested HDN_BEGINTRACK and HDN_ENDTRACK, and these are working well.

I also changed the Control Id of message map to IDC_TEST_LIST and 0, there was no difference - it is still not working.

I searched many forums, but I couldn't find any solution.

Here's my test code.


BEGIN_MESSAGE_MAP(CDlgTest, CDialogEx)
    //ON_NOTIFY(HDN_BEGINTRACK, 0, &CDlgTest::OnTrackListTest) // WORKING!!
    //ON_NOTIFY(HDN_ENDTRACK, 0, &CDlgTest::OnTrackListTest) // WORKING!!
    //ON_NOTIFY(HDN_TRACK, IDC_TEST_LIST, &CDlgTest::OnTrackListTest) // NOT WORKING
    ON_NOTIFY(HDN_TRACK, 0, &CDlgTest::OnTrackListTest)   // NOT WORKING
END_MESSAGE_MAP()


void CDlgTest::OnTrackListLog(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
    // TODO: Add your control notification handler code here

    AfxMessageBox(L"Hello!!!");     // >>>>>>>>>>> NOT showing up

    *pResult = 0;
}


class CDlgTest : public CDialogEx {
    
public:
    afx_msg void OnTrackListLog(NMHDR* pNMHDR, LRESULT* pResult);
}

I append some forums that I visited:

What can I try next?

Upvotes: 1

Views: 454

Answers (2)

Barmak Shemirani
Barmak Shemirani

Reputation: 31629

This is an odd behavior with header control, it's described in HDN_TRACK and HDS_FULLDRAG also posted by @Constantine

You have to remove HDS_FULLDRAG style from header control in OnInitDialog:

m_list.GetHeaderCtrl()->ModifyStyle(HDS_FULLDRAG, 0);

Then you should receive HDN_TRACK message

void CDlgTest::OnTrack(NMHDR* pNMHDR, LRESULT* pResult)
{
    TRACE(L"OnTrack\n");
    *pResult = 0;
}

ON_NOTIFY(HDN_TRACK, 0, OnTrack)

But now you don't have HDS_FULLDRAG style! If HDS_FULLDRAG flag is required, then don't change in OnInitDialog. Instead, you can enable/disable HDS_FULLDRAG in response to HDN_BEGINTRACK/HDN_ENDTRACK

Upvotes: 2

Constantine Georgiou
Constantine Georgiou

Reputation: 3401

First try HDN_TRACKA or HDN_TRACKW instead of HDN_TRACK and see if these work. Normally HDN_TRACK is defined correctly as either of the two according to your project settings, but better try both.

Also, searched a little bit on the i-net and found that a list-control with the HDS_FULLDRAG style set sends the HDN_ITEMCHANGINGrather than the HDN_TRACK notification. The article dates back to 2004!...

So you can try either removing that style, if this is OK to you, or capturing the HDN_ITEMCHANGING notification instead. The style can be set or removed by changing the initial creation style-flags if it created programmatically, by changing the resource file (or using the property editor) if it is created using a dialog resource, or by calling GetWindowLong()/SetWindowLong() after it is created.

Upvotes: 2

Related Questions