Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top