Re: Deriving from CCtrlView
Fernando G?mez wrote:
The new CMFCListCtrl class, included with the VC9's feature pack, is
cool. I wanted to use it for my CListView's instead of the old one.
After some research, I saw that there was nothing I could to to replace
old CListCtrl with CMFCListCtrl in the view. So I decided to create my
I was planning on deriving a class from CCtrlView (CListView's parent
BTW) and while researching, I came across an article by Tom Archer.
In this article, he explains how to do this. He suggest that one should
specify in the CCtrlView's first parameter the name of the window's class.
So, I thought that such thing would be an easy way to solve my problem.
I thus spy++'ed and discovered that CMFCListCtrl's class name is
"SysListView32", the same for the CListCtrl I want to avoid. Or course,
I should have noted that CMFCListCtrl will only override some message
handling to do the cool stuff it does.
So now my question is, is there any way I can do what I want deriving
from CCtrlView (perhaps I'm missing something)? Or should I go one step
further and instead derive from CView and handle all the resizing, etc,
Ah, never mind. I already derived it from CView, what the hell. It was
easy anyway. So, here's the code in case someone is interested.
class CMFCListView : public CView
virtual int OnCreate(LPCREATESTRUCT lpcs);
virtual void OnSize(UINT nType, int cx, int cy);
virtual void OnDraw(CDC* pDC);
virtual void InitList();
int CMFCListView::OnCreate(LPCREATESTRUCT lpcs)
bResult = CView::OnCreate(lpcs) == -1;
if (bResult == -1) return bResult;
dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | LVS_REPORT;
bResult = m_wndListCtrl.Create(dwStyle, CRect(0, 0, 0, 0),
return bResult ? 0 : -1;
void CMFCListView::OnSize(UINT nType, int cx, int cy)
CView::OnSize(nType, cx, cy);
m_wndListCtrl.MoveWindow(0, 0, cx, cy, TRUE);
void CMFCListView::OnDraw(CDC* pDC)