www.gusucode.com > VC++编写的SQL服务端和客户端源码程序 > VC++编写的SQL服务端和客户端源码程序\code\Client\SelView.cpp

    // SelView.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "Client.h"
#include "SelView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSelView

IMPLEMENT_DYNCREATE(CSelView, CListView)

CSelView::CSelView()
{
	ItemIndex = 0;
}

CSelView::~CSelView()
{
}

BOOL CSelView::PreCreateWindow( CREATESTRUCT& cs )
{
	cs.style |= LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS;

	return CListView::PreCreateWindow( cs );
}

BEGIN_MESSAGE_MAP(CSelView, CListView)
	//{{AFX_MSG_MAP(CSelView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSelView drawing

void CSelView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CSelView diagnostics

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

void CSelView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSelView message handlers

void CSelView::InsertCol( CMsg& msg )
{
	CListCtrl&	theCtrl = GetListCtrl();
	LV_COLUMN	LVColumn;
	int count = msg.m_msgList.GetCount() / 2;

	DWORD dwStyle = ListView_GetExtendedListViewStyle( GetListCtrl() );
	dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES
			| LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;
	ListView_SetExtendedListViewStyle (GetListCtrl(),dwStyle);

	theCtrl.DeleteAllItems();

	LVColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	
	POSITION pos = msg.m_msgList.GetHeadPosition();
	for ( int column = 0; column < count; column ++ ){
		LVColumn.fmt = LVCFMT_RIGHT;

		CString temp;
		temp = msg.m_msgList.GetNext( pos );
		LVColumn.pszText = (LPTSTR)(LPCTSTR)temp;

		temp = msg.m_msgList.GetNext( pos );
		int len;
		::sscanf( (LPCTSTR)temp, "%d", &len );
		LVColumn.cx = len;

		LVColumn.iSubItem = column;
		theCtrl.InsertColumn( column, &LVColumn );
	}
}

void CSelView::InsertItem( CMsg& msg )
{
	CListCtrl&	theCtrl = GetListCtrl();
	int			count = msg.m_msgList.GetCount();
	
	POSITION	pos = msg.m_msgList.GetHeadPosition();
	CString		temp;
	temp = msg.m_msgList.GetNext( pos );
	int curItemIndex = theCtrl.InsertItem( LVIF_TEXT | LVIF_PARAM, ItemIndex++, temp, 0, 0, 0, 0 );

	for( int SubItemIndex = 1; SubItemIndex < count; SubItemIndex++ )
	{
		temp = msg.m_msgList.GetNext( pos );
		theCtrl.SetItem( curItemIndex, SubItemIndex, LVIF_TEXT, temp, 0, 0, 0, 0 );
	}
}