views:

949

answers:

3

I'd like to use the new CMFCListCtrl features with my CListView class (and, of course, the new CMFCHeaderCtrl inside it). Unfortunately, you can't use Attach() or SubclassWindow() because the SysListView32 window is already associated with a CListView object.

Do I have to override CListView's OnCmdMsg() and route all messages to my own instance of CMFCListCtrl? (Will that even work?) Or is there an easier/cleaner solution?

+1  A: 

I'd inherit from CFormView and let the CMFCListCtrl occupy the complete dialog of the form view.

fhe
There's a little extra cruft from the form dialog and handling size changes to keep the list occupying the entire dialog. It might be just as good to subclass CView and create CMyListCtrl in OnCreate(). I'll have to see how well I can retrofit that before I accept the answer. Thanks!
skst
Good luck, please let me know whether it has worked for you.
fhe
Since I only needed a single control, I derived from CView instead of CFormView, but it's the same principle.
skst
+1  A: 

CListView doesn't have a lot of functionality. Like you said in the comment above, just derive your own view class from CView, handle WM_SIZE to resize the CMFCListCtrl and you're good to go.

Roel
A: 

If you want your own CMFCHeaderCtrl (f.e. m_myHeaderCtrl derived from CMFCHeaderCtrl) you have to override these three functions in your own CMFCListCtrl

CMFCHeaderCtrl& CMyMFCListCtrl::GetHeaderCtrl() { return m_myHeaderCtrl; }

void CMyMFCListCtrl::InitHeader() { // Initialize header control: m_myHeaderCtrl.SubclassDlgItem(0, this); }

void CMyMFCListCtrl::OnSize(UINT nType, int cx, int cy) { CListCtrl::OnSize(nType, cx, cy); if (myHeaderCtrl.GetSafeHwnd() != NULL) { myHeaderCtrl.RedrawWindow(); } }

Now you have the full responce in your own myHeaderCtrl defining some more functions (f.e. multipe lines in header):

OnDrawItem(CDC* pDC, int iItem, CRect rect, BOOL bIsPressed, BOOL bIsHighlighted);

or defining your own layout by

afx_msg LRESULT OnHeaderLayout(WPARAM wp, LPARAM lp);

Examples are in the MFC-Code.

Frekers