Click here to Skip to main content
13,662,169 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

9.9K views
2 bookmarked
Posted 6 Nov 2011
Licenced CPOL

Missing CMFCListView class

, 6 Nov 2011
Rate this:
Please Sign up or sign in to vote.
How to implement the missing CMFCListView class.

Since Microsoft forgot to implement the CMFCListView class, I found a solution[^]. The CMFCListCtrl class extends the functionality of the CListCtrl class by supporting the advanced header control functionality of the CMFCHeaderCtrl class.

MFCListView.h : header file
class CMFCListView : public CFormView
{
    DECLARE_DYNCREATE(CMFCListView)
 
protected:
    CMFCListView();           // protected constructor used by dynamic creation
    virtual ~CMFCListView();
 
public:
    enum { IDD = IDD_MFCLISTVIEW };
#ifdef _DEBUG
    virtual void AssertValid() const;
#ifndef _WIN32_WCE
    virtual void Dump(CDumpContext& dc) const;
#endif
#endif
 
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
public:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnDestroy();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    virtual void OnInitialUpdate();
    virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
    CMFCListCtrl& GetListCtrl() { return m_mfcListCtrl; }
 
protected:
    CMFCListCtrl m_mfcListCtrl;
 
    DECLARE_MESSAGE_MAP()
};
MFCListView.cpp : implementation file
#define ID_MFCLISTCTRL (WM_USER+0x1234)
 
IMPLEMENT_DYNCREATE(CMFCListView, CFormView)
 
CMFCListView::CMFCListView()
    : CFormView(CMFCListView::IDD)
{
}
 
CMFCListView::~CMFCListView()
{
}
 
void CMFCListView::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);
}
 
BEGIN_MESSAGE_MAP(CMFCListView, CFormView)
    ON_WM_CREATE()
    ON_WM_DESTROY()
    ON_WM_SIZE()
    ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
 
// CMFCListView diagnostics

#ifdef _DEBUG
void CMFCListView::AssertValid() const
{
    CFormView::AssertValid();
}
 
#ifndef _WIN32_WCE
void CMFCListView::Dump(CDumpContext& dc) const
{
    CFormView::Dump(dc);
}
#endif
#endif //_DEBUG

// CMFCListView message handlers

int CMFCListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFormView::OnCreate(lpCreateStruct) == -1)
        return -1;
 
    if (!m_mfcListCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | 
            LVS_SHOWSELALWAYS, CRect(0, 0, 0, 0), this, ID_MFCLISTCTRL))
        return -1;
 
    return 0;
}
 
void CMFCListView::OnDestroy()
{
    CFormView::OnDestroy();
 
    VERIFY(m_mfcListCtrl.DestroyWindow());
}
 
void CMFCListView::OnSize(UINT nType, int cx, int cy)
{
    CFormView::OnSize(nType, cx, cy);
 
    if (m_mfcListCtrl.GetSafeHwnd() != NULL)
        m_mfcListCtrl.MoveWindow(0, 0, cx, cy);
}
 
BOOL CMFCListView::OnEraseBkgnd(CDC* pDC)
{
    // return CFormView::OnEraseBkgnd(pDC);

    return TRUE;
}
 
void CMFCListView::OnInitialUpdate()
{
    CFormView::OnInitialUpdate();
 
    SetScrollSizes(MM_TEXT, CSize(0, 0));
}
 
BOOL CMFCListView::OnCmdMsg(UINT nID, int nCode, 
     void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    if (m_mfcListCtrl.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;
 
    return CFormView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mihai MOGA
Architect Printec Group Romania SRL
Romania Romania
My professional background includes knowledge of analyst programmer for Microsoft Visual C++, Microsoft Visual C#, Microsoft Visual Basic, Sun Java, assembly for Intel 80x86 microprocessors, assembly for PIC microcontrollers (produced by Microchip Inc.), relational databases (MySQL, Oracle, SQL Server), concurrent version systems, bug tracking systems, web design (HTML5, CSS3, XML, PHP/MySQL, JavaScript, Flash).

If you like my articles, please visit my website for more: http://www.mihaimoga.com/

You may also be interested in...

Comments and Discussions

 
GeneralWhy don't you like CListView? It is inherited from CCtrlView... Pin
Nick Kulikovsky10-Nov-11 15:14
memberNick Kulikovsky10-Nov-11 15:14 
GeneralRe: CListView is using CListCtrl, and I wanted to use the functi... Pin
Mihai MOGA12-Nov-11 20:56
memberMihai MOGA12-Nov-11 20:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 6 Nov 2011
Article Copyright 2011 by Mihai MOGA
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid