www.pudn.com > virtualListview_demo.zip > listview_exampleView.cpp
// listview_exampleView.cpp : implementation of the CListview_exampleView class
//
#include "stdafx.h"
#include "listview_example.h"
#include "listview_exampleDoc.h"
#include "listview_exampleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CListview_exampleView
IMPLEMENT_DYNCREATE(CListview_exampleView, CView)
BEGIN_MESSAGE_MAP(CListview_exampleView, CView)
//{{AFX_MSG_MAP(CListview_exampleView)
ON_WM_DESTROY()
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListview_exampleView construction/destruction
CListview_exampleView::CListview_exampleView()
{
linkedlist = NULL;
}
CListview_exampleView::~CListview_exampleView()
{
}
BOOL CListview_exampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CListview_exampleView drawing
void CListview_exampleView::OnDraw(CDC* pDC)
{
CListview_exampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CListview_exampleView diagnostics
#ifdef _DEBUG
void CListview_exampleView::AssertValid() const
{
CView::AssertValid();
}
void CListview_exampleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CListview_exampleDoc* CListview_exampleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CListview_exampleDoc)));
return (CListview_exampleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CListview_exampleView message handlers
void CListview_exampleView::OnDestroy()
{
CView::OnDestroy();
FreeAll(linkedlist);
}
int CListview_exampleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
//create list control
m_list.Create(WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_OWNERDATA, CRect(1, 2, 3, 4), this, 1);
m_list.InsertColumn(0, "Field 1");
m_list.InsertColumn(1, "Field 2");
m_list.InsertColumn(2, "Field 3");
m_list.SetColumnWidth(0, 200);
m_list.SetColumnWidth(1, 200);
m_list.SetColumnWidth(2, 200);
return 0;
}
void CListview_exampleView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
m_list.MoveWindow(0, 0, cx, cy);
}
//add items to listctrl
void CListview_exampleView::AddItems(int count)
{
if(count <= 0)
return;
int i;
for(i = 0; i < count; i++)
linkedlist = CreateNode(linkedlist, i);
m_list.AddItem(linkedlist, count);
}