Re: Deriving from CCtrlView
Fernando G?mez wrote:
Hello all.
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
own view.
I was planning on deriving a class from CCtrlView (CListView's parent
BTW) and while researching, I came across an article by Tom Archer[1].
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,
by myself?
Regards,
Fernando.
[1] http://www.developer.com/net/cplus/article.php/627681
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.
// mfclistview.h
#pragma once
class CMFCListView : public CView
{
DECLARE_DYNCREATE(CMFCListView);
DECLARE_MESSAGE_MAP();
public:
CMFCListView();
virtual ~CMFCListView();
CMFCListCtrl& GetListCtrl();
protected:
virtual int OnCreate(LPCREATESTRUCT lpcs);
virtual void OnSize(UINT nType, int cx, int cy);
virtual void OnDraw(CDC* pDC);
virtual void InitList();
private:
CMFCListCtrl m_wndListCtrl;
};
// mfclistview.cpp
#include "stdafx.h"
#include "mfclistview.h"
IMPLEMENT_DYNCREATE(CMFCListView, CView);
BEGIN_MESSAGE_MAP(CMFCListView, CView)
ON_WM_CREATE()
ON_WM_SIZE()
END_MESSAGE_MAP();
CMFCListView::CMFCListView()
: CView()
{
}
CMFCListView::~CMFCListView()
{
}
int CMFCListView::OnCreate(LPCREATESTRUCT lpcs)
{
DWORD dwStyle;
BOOL bResult;
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),
this, 1);
InitList();
return bResult ? 0 : -1;
}
void CMFCListView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (::IsWindow(m_wndListCtrl))
m_wndListCtrl.MoveWindow(0, 0, cx, cy, TRUE);
}
void CMFCListView::OnDraw(CDC* pDC)
{
}
void CMFCListView::InitList()
{
}
CMFCListCtrl& CMFCListView::GetListCtrl()
{
return m_wndListCtrl;
}
//
Regards,
Fernando.