Click here to Skip to main content
15,900,378 members

Comments by william basser (Top 1 by date)

william basser 6-Feb-13 11:11am View    
// TestListViewView.cpp : implementation of the CTestListViewView class
//

#include "stdafx.h"
#include "TestListView.h"

#include "TestListViewDoc.h"
#include "TestListViewView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CTestListViewView

IMPLEMENT_DYNCREATE(CTestListViewView, CListView)

BEGIN_MESSAGE_MAP(CTestListViewView, CListView)
ON_COMMAND(ID_EDIT_TEST, &CTestListViewView::OnEditTest)
ON_COMMAND(ID_VIEW_LIST, &CTestListViewView::OnViewList)
ON_COMMAND(ID_VIEW_DETAILS, &CTestListViewView::OnViewDetails)
END_MESSAGE_MAP()

// CTestListViewView construction/destruction

CTestListViewView::CTestListViewView()
{
// TODO: add construction code here

}

CTestListViewView::~CTestListViewView()
{
}

BOOL CTestListViewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style &= ~LVS_TYPEMASK;
cs.style |= LVS_REPORT;

return CListView::PreCreateWindow(cs);
}

void CTestListViewView::OnInitialUpdate()
{
CListView::OnInitialUpdate();

CListCtrl &listTest = GetListCtrl( );
CHeaderCtrl* phdrTest = listTest.GetHeaderCtrl( );

// create a item
HDITEM hdiItem;
hdiItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
hdiItem.cxy = 150;
hdiItem.fmt = HDF_STRING | HDF_LEFT;
hdiItem.pszText = _T( "Column1" );
phdrTest->InsertItem( 0, &hdiItem );
hdiItem.pszText = _T( "Column2" );
phdrTest->InsertItem( 1, &hdiItem );
}


// CTestListViewView diagnostics

#ifdef _DEBUG
void CTestListViewView::AssertValid() const
{
CListView::AssertValid();
}

void CTestListViewView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}

CTestListViewDoc* CTestListViewView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestListViewDoc)));
return (CTestListViewDoc*)m_pDocument;
}
#endif //_DEBUG


// CTestListViewView message handlers

void CTestListViewView::OnEditTest()
{
// get the list contro
CListCtrl &listTest = GetListCtrl( );

// fill
CString strTemp;
for ( int i = 0; i < 50; i++ )
{
strTemp.Format( _T( "Test: %d" ), i );
listTest.InsertItem( i, strTemp );
strTemp.Format( _T( "Col2: %d" ), i );
listTest.SetItemText( i, 1, strTemp );
}


UpdateData( false );
}

void CTestListViewView::OnViewList()
{
// TODO: Add your command handler code here
LONG lStyle = GetWindowLong( m_hWnd, GWL_STYLE );
lStyle &= ~LVS_TYPEMASK;
lStyle |= LVS_LIST;
SetWindowLong( m_hWnd, GWL_STYLE, lStyle );
}

void CTestListViewView::OnViewDetails()
{
// TODO: Add your command handler code here
LONG lStyle = GetWindowLong( m_hWnd, GWL_STYLE );
lStyle &= ~LVS_TYPEMASK;
lStyle |= LVS_REPORT;
SetWindowLong( m_hWnd, GWL_STYLE, lStyle );
}