views:

67

answers:

2

CListCtrl has a CHeaderCtrl 'built-in' and we want to override it with something customized, i.e a class which derives from CHeaderCtrl.

What's the best/correct way to do this, assuming we have a dialog CMyDlg which contains a CListCtrl m_List, and a custom header CCustomHeader.

A: 

Derive a class from CListCtrl and implement the handlers for the notification messages you need. The messages are named with LVN_ for messages about the list control and its items, and also HDN_ for things about the header control.

dwo
How does this fit in with CListCtrl::GetHeaderCtrl?
John
The messages of the header control are routed to its container, the list control. If you need to modify the header, you have to use `this->GetHeaderCtrl()->whatever`.
dwo
+1  A: 

You should be able to call CWnd::SubclassWindow from your CCustomHeader member variable.

m_Header.SubclassWindow(m_List.GetHeaderCtrl()->GetSafeHwnd());
Mark Ransom
It's a good idea to do this in PreSubClassWindow of the list control (provided you derive your own list control).
humbagumba