skst
skst

Reputation: 627

How to use CMFCListCtrl with CListView?

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?

Upvotes: 1

Views: 4081

Answers (3)

Frekers
Frekers

Reputation: 21

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.

Upvotes: 2

Roel
Roel

Reputation: 19642

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.

Upvotes: 1

fhe
fhe

Reputation: 6187

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

Upvotes: 2

Related Questions