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?
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