Click to See Complete Forum and Search --> : How to catch LVN_COLUMNCLICK in a subclassing ListViewCtrl


Zhuang Yuyao
April 7th, 1999, 07:23 AM
As I created an ActiveX control which subclassed Windows control SysListView32, I tried to catch the message LVN_COLUMNCLICK which generated when i clicked the header of my listview control, but OnOcmCommand failed, it is not even called.

Can anyone give me some help? I also want to catch the message of mouse click and double click.

thank you very much!

April 7th, 1999, 02:09 PM
This works for me:

In the CPP file:

BEGIN_MESSAGE_MAP(MyListCtrl, CListCtrl)
//{{AFX_MSG_MAP(MyListCtrl)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// This is a reflected message handler, which means that this control
// handles this message instead of the parent window. Any handler
// for this message in the parent window will override this handler
// (unless it calls this handler first, of course).
void MyListCtrl::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*) pNMHDR;

DoCoolStuffLikeSortColumn(pNMListView->iSubItem);
*pResult = 0;
}

... and in the H file:

afx_msg void OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);

HTH!

Zhuang Yuyao
April 7th, 1999, 08:41 PM
LVN_COLUMNCLICK is a WM_NOTIFY format message rather than a WM_COMMAND one, and can not be caught by OnOcmCommand.

Here are some code of mine, wish it will be helpful to someone:

ON_MESSAGE(OCM_NOTIFY, OnOcmNotify)

LRESULT CMyListCtrl::OnOcmNotify(WPARAM wParam, LPARAM lParam)
{
NMHDR * pNMHDR = (NMHDR *)lParam;
UINT nNotifyCode = pNMHDR->code;
switch (nNotifyCode)
{
case LVN_COLUMNCLICK:
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lParam;
......
break;
}

return 0;
}