首页
社区
课程
招聘
[分享]分享一下CListCtrl类的重画子类~!
发表于: 2009-7-29 16:00 16004

[分享]分享一下CListCtrl类的重画子类~!

2009-7-29 16:00
16004
一个MFC类的子类,方便大家使用,画的不好,希望见量,LIST的样子和OD差不多,很多东西都可以实现了,比起原版的要强大些,实际一个不难的东西,google找到的X站,是需要会员可以下的,会员注册是需要RMB的,无法偷懒,只有自己动手。

头文件:
#if !defined(AFX_MGLISTCTRLBASE_H__5688F862_FD2E_42A5_9999_9369060BD7AE__INCLUDED_)
#define AFX_MGLISTCTRLBASE_H__5688F862_FD2E_42A5_9999_9369060BD7AE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MgListCtrlBase.h : header file
//

//--------------------------------------------------------------------------------------------------------------------------
//关键重画部分已经使用类虚拟函数,如果需要那部分重画,直接子类化重载,将绘画部分和重载分开,方便做默认处理^^.
//LVS_OWNERDATA属性似乎无法用代码开启,似乎是在控件创建时设定,但是当在对话框初始化函数中时,控件已经创建完成,
//所以,在使用的时候需要手动开启CListCtrl控件的该属性.
//如果是VC6,需要开启:
#pragma warning(disable:4786)		//需要注释掉warning,std::map 模板版本兼容问题,存在警告~!
#include <map>
#include <vector>
#include <algorithm>


//--------------------------------------------------------------------------------------------------------------------------
//常量声明:
#define		_MGLCB_FONTNML_HEIGHT_	12

//--------------------------------------------------------------------------------------------------------------------------
//类声明:
class		CMgListCtrlBaseInfo
{
public:
	CMgListCtrlBaseInfo();
	virtual ~CMgListCtrlBaseInfo();

public:
	typedef		struct		_tagItemInfo_
	{
		int			nIndex;		//列号
		int			nTextLen;	//字符串长度
		CString		strText;	//字符串
	}_T_ITEMINFO_;


protected:
	//由原来的map改为vector,提高速度:
	//读取临时使用at,设置为清除插入方法.
	std::vector< _T_ITEMINFO_ >		m_vtrItemInfo;

private:
	int		m_nIndex;

public:
	int			ClearItemInfo();

	//
	int			GetIndex();
	int			SetIndex( int nIndex );
	
	//
	int			SetItemText( int nColumn , LPCTSTR pszText );
	int			GetItemText( int nColumn , LPTSTR pszText , int nTextLen );
	CString		GetItemText( int nColumn );

};

//--------------------------------------------------------------------------------------------------------------------------
//类声明:
/////////////////////////////////////////////////////////////////////////////
// CMgListCtrlBase window

class CMgListCtrlBase : public CListCtrl
{
// Construction
public:
	CMgListCtrlBase();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMgListCtrlBase)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CMgListCtrlBase();

	// Generated message map functions
protected:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);

	//{{AFX_MSG(CMgListCtrlBase)
		// NOTE - the ClassWizard will add and remove member functions here.
	afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

protected:
	virtual	void	DrawItemFocus( int nType ,CDC * pDC , UINT nItemID );
	virtual	void	DrawItemSelect( CDC * pDC , UINT nItemID );
	virtual void	DrawCellText( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect );
	virtual void	DrawCellState( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect );
	virtual	void	DrawCustomInfo( CDC * pDC , UINT nItemID );

protected:
	void	DrawItemBase(LPDRAWITEMSTRUCT lpDrawItemStruct);
	void	DrawItemMainBase( CDC * pDC , UINT nItemID , int nType );
	int		DrawItemFocusBase( int nType , CDC * pDC , UINT nItemID );
	int		DrawItemSelectBase( CDC * pDC , UINT nItemID );
	int		DrawGridLineBase( CDC * pDC , UINT nItemID );
	int		DrawCellBase( CDC * pDC , UINT nItemID );
	int		DrawCellTextBase( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect  );
	int		DrawCellStateBase( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect );

//-----------------------------------------------------------------------------
//重载CListCtrl类:枚举声明
public:
	typedef		enum	_enum_ListCtrlStyle_
	{
		_E_LCS_SmallIcon_				= LVS_SMALLICON,
		_E_LCS_Icon_					= LVS_ICON,
		_E_LCS_List_					= LVS_LIST,
		_E_LCS_Report_					= LVS_REPORT,
		_E_LCS_SelAlways_				= LVS_SHOWSELALWAYS,
		_E_LCS_ReportAndShowSelAlways_	= LVS_REPORT | LVS_SHOWSELALWAYS
	}_enum_LCS_;
	
	
	typedef		enum	_enum_ListItemState_
	{
		_E_LIS_Normal_			=	0,
		_E_LIS_Default_			=	0,
		_E_LIS_Select_			=	1,
		_E_LIS_Focus_			=	2,
		_E_LIS_SelAndFocus_		=	_E_LIS_Select_ | _E_LIS_Focus_
			
	}_enum_LIS_;
	
	typedef		enum	_enum_ListGridLine_
	{
		_E_LGL_Normal_			=	0,
		_E_LGL_Default_			=	0,
		_E_LGL_VLine_			=	1,
		_E_LGL_HLine_			=	2,
		_E_LGL_HVLine_			=	_E_LGL_VLine_ | _E_LGL_HLine_
			
	}_enum_LGL_;

	
	
//-----------------------------------------------------------------------------
//重载CListCtrl类:结构声明
public:
	typedef		struct	_tagListCellState_ 
	{
		int			nItem;
		int			nSubItem;
		COLORREF	clrBk;
		COLORREF	clrTxt;
	}_T_LCS_;


//-----------------------------------------------------------------------------
//重载CListCtrl类:变量声明
public:
	//默认颜色:
	COLORREF		m_clrNmlBackGround;
	COLORREF		m_clrNmlTxtBackGround;
	COLORREF		m_clrNmlTxt;
	
	//焦点和网格颜色: 
	//焦点:0不选择,1选择
	//网格:0是纵向,1是横向
	COLORREF		m_clrFocusLine[2];
	COLORREF		m_clrGridLine[2];
	
	//选择颜色
	COLORREF		m_clrSelBackGround;
	COLORREF		m_clrSelTxt;
	
	//单元格颜色:
	std::map<int,_T_LCS_>	m_mapListCellState;
	std::map<int,_T_LCS_>	m_mapListFullCellState;

	//多数据量处理信息:
	std::map<int,CMgListCtrlBaseInfo>		m_mapListInfo;

public:
	
	//项目高度:默认为字体高度 * 78 / 72
	int				m_nItemHeight;
	
	//列表框全部字体:
	CFont			m_fontAllItemFont;
	
	//是否重画焦点线框:
	BOOL			m_bDrawFocusLine;
	
	//网格线状态:
	int				m_nGridLineState;
	
	//是否显示项目:
	BOOL			m_bYesNoShowItem;

	//是否按大项目来处理处理
	BOOL			m_bYesNoOwnerData;


//-----------------------------------------------------------------------------
//重载CListCtrl类:函数声明
public:
	//-----------------------------------------------
	//GetFullCellRect : 列表控件整行矩形
	//-----------------------------------------------
	int			GetFullCellRect( int nItem , LPRECT lpRect );
	
	//-----------------------------------------------
	//GetCellRect : 列表控件单元格矩形
	//-----------------------------------------------
	int			GetCellRect( int nItem , int nSubItem , LPRECT lpRect );
	
	//-----------------------------------------------
	//SetSelItem: 设置列表控件选择项目
	//-----------------------------------------------
	int			SetSelItem( int nIndex );
	int			SetSelItemAndFocus( int nIndex );
	
	//-----------------------------------------------
	//SetTxtFont : 设置列表控件纯文本字体
	//-----------------------------------------------
	BOOL		SetAllTxtFont( int nFontSize , char * szFontName = _T("宋体"), BOOL bRedraw = TRUE );
	CFont *		GetAllTxtFont( );

	//-----------------------------------------------
	//ClearAllItems : 清空所有项目
	//-----------------------------------------------
	int			ClearAllItems( );

public:
	//-----------------------------------------------
	//SetStyle : 设置列表控件风格
	//-----------------------------------------------
	int			SetStyle( _enum_LCS_	lcs /*= _ENUM_LCS_Report_*/ );
	int			SetStyle( DWORD dwStyle = LVS_REPORT );

	//-----------------------------------------------
	//SetExStyle : 设置列表控件扩展风格
	//-----------------------------------------------
	int			SetExStyle( DWORD dwStyle = LVS_EX_FULLROWSELECT );

	//-----------------------------------------------
	//SetShowItem : 是否显示项目(可以选择否,等添加完成项目,再显示,提高速率.)
	//-----------------------------------------------
	BOOL		SetShowItem( BOOL bShow = TRUE );

	//-----------------------------------------------
	//SetOwnerDraw : 设置列表控件是否重画
	//-----------------------------------------------
	int			SetOwnerDraw( BOOL bDraw = FALSE );

	//-----------------------------------------------
	//SetOwnerData : 设置列表控件是否按大数据量来处理项目,默认否.
	//-----------------------------------------------
	int			SetOwnerData( BOOL bOwnerData = FALSE );

	//-----------------------------------------------
	//SetShowFocus : 是否显示焦点线框
	//-----------------------------------------------
	BOOL		SetShowFocus( BOOL bShow = TRUE , COLORREF clrNml = RGB(0,0,0) , COLORREF clrSel = RGB(255, 255, 255) );

	//-----------------------------------------------
	//SetGridLineState : 设置网格线
	//-----------------------------------------------
	void		SetGridLineState( int	nMgState = -1 , int nNmlState = -1 , 
								COLORREF clrV = RGB( 150, 150, 150 ) , COLORREF clrH = RGB(150, 150, 150 ) );


	//-----------------------------------------------
	//SetItemHeight : 设置列表控件项目高度
	//-----------------------------------------------
	void		SetItemHeight( int nHeight );

public:

	//-----------------------------------------------
	//SetNmlColor : 设置列表控件默认背景
	//-----------------------------------------------
	BOOL		SetNmlBkColor( COLORREF	color );
	COLORREF	GetNmlBkColor( );
	
	//-----------------------------------------------
	//SetTxtBkColor : 设置列表控件纯文本背景
	//-----------------------------------------------
	BOOL		SetNmlTxtBkColor( COLORREF	color );
	COLORREF	GetNmlTxtBkColor( );
	
	//-----------------------------------------------
	//SetTxtColor : 设置列表控件纯文本颜色
	//-----------------------------------------------
	BOOL		SetNmlTxtColor( COLORREF	color );
	COLORREF	GetNmlTxtColor( );
	
	//-----------------------------------------------
	//SetSelBkColor : 设置列表控件选择时背景
	//-----------------------------------------------
	BOOL		SetSelBkColor( COLORREF	color );
	COLORREF	GetSelBkColor( );
	
	//-----------------------------------------------
	//SetSelTxtColor : 设置列表控件选择时文本颜色
	//-----------------------------------------------
	BOOL		SetSelTxtColor( COLORREF	color );
	COLORREF	GetSelTxtColor( );
	
	//-----------------------------------------------
	//SetCellColor : 设置单元格颜色
	//-----------------------------------------------
	void	SetCellColor( int nItem , int nColumn , COLORREF clrBackground = (COLORREF)-1, COLORREF	clrTxt =(COLORREF)-1 );
	void	DelCellColor( int nItem , int nColumn );
	
	//-----------------------------------------------
	//SetFullCellColor : 设置整行颜色
	//-----------------------------------------------
	void	SetFullCellColor( int nItem , COLORREF clrBackground = (COLORREF)-1, COLORREF	clrTxt =(COLORREF)-1 );
	void	DelFullCellColor( int nItem );

	
//-----------------------------------------------------------------------------
//重载CListCtrl类:大数据项目相关函数声明:
protected:
	virtual void	vl_DrawCellText( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect );

protected:
	int		vl_DrawCellTextBase( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect  );


public:
	//-----------------------------------------------
	//vl_InsertItem : 向列表控件插入项目
	//-----------------------------------------------
	int		vl_InsertItem( int nItem , LPCTSTR	strItem , BOOL bUpdate = TRUE ); 

	//-----------------------------------------------
	//vl_DeleteItem : 删除列表控件指定项目
	//-----------------------------------------------
	int		vl_DeleteItem( int nItem ); 
	int		vl_DeleteAllItems( );

	//-----------------------------------------------
	//vl_SetItemText : 设置列表控件指定项目文本
	//-----------------------------------------------
	int		vl_SetItemText( int nItem, int nColumn , LPCTSTR pszItem ); 

	//-----------------------------------------------
	//vl_GetItemText : 获取列表控件指定项目文本
	//-----------------------------------------------
	int		vl_GetItemText( int nItem , int nColumn , LPTSTR pszItem , int nItemLen );
	CString vl_GetItemText( int nItem , int nColumn );

};






//--------------------------------------------------------------------------------------------------------------------------
//
/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MGLISTCTRLBASE_H__5688F862_FD2E_42A5_9999_9369060BD7AE__INCLUDED_)



代码文件
// MgListCtrlBase.cpp : implementation file
//

#include "stdafx.h"
#include "MgListCtrlBase.h"

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



//---------------------------------------------------------------------------------------------------------------------------
//											----- 构造函数 ------
//---------------------------------------------------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// CMgListCtrlBaseInfo
CMgListCtrlBaseInfo::CMgListCtrlBaseInfo()
{
	ClearItemInfo();
}

CMgListCtrlBaseInfo::~CMgListCtrlBaseInfo()
{
	//
}

//-----------------------------------------------------------------------
//清除处理:
//
//-----------------------------------------------------------------------
int			CMgListCtrlBaseInfo::ClearItemInfo()
{
	//
	m_nIndex		= -1;
	
	//
	m_vtrItemInfo.clear();

	return 0;
}

//-----------------------------------------------------------------------
//索引处理:
//
//-----------------------------------------------------------------------
int			CMgListCtrlBaseInfo::GetIndex()
{
	return m_nIndex;
}

int			CMgListCtrlBaseInfo::SetIndex( int nIndex )
{
	int nResult = m_nIndex ;
	m_nIndex = nIndex ;
	return nResult;
}


//-----------------------------------------------------------------------
//设置项目文本处理:
//
//-----------------------------------------------------------------------
int			CMgListCtrlBaseInfo::SetItemText( int nColumn , LPCTSTR pszText )
{
	if( nColumn < 0 || pszText == NULL ){ return -1; }
	
	
	_T_ITEMINFO_	info;
	info.nIndex  = nColumn;
	info.nTextLen= strlen(pszText);
	info.strText = pszText;
	
	//先清除元素,再插入:
	//这个方法不大妥当:m_vtrItemInfo[nColumn] = info;
	if( m_vtrItemInfo.end() > m_vtrItemInfo.begin() + nColumn )
	{
		m_vtrItemInfo.erase( m_vtrItemInfo.begin() + nColumn );
	}
	if( m_vtrItemInfo.size() < nColumn ){ return -1; }
	m_vtrItemInfo.insert( m_vtrItemInfo.begin() + nColumn , info );

	return nColumn;
}


//-----------------------------------------------------------------------
//获取项目文本处理:
//
//-----------------------------------------------------------------------
int			CMgListCtrlBaseInfo::GetItemText( int nColumn , LPTSTR pszText , int nTextLen )
{
	if( nColumn < 0 || pszText == NULL ){ return 0; }
	if( m_vtrItemInfo.size() <= nColumn ){ pszText[0] = '\0'; return 0; }

	//
	int nLen = m_vtrItemInfo.at( nColumn ).nTextLen;
	if( nLen >= nTextLen )
	{
		memcpy( pszText , m_vtrItemInfo.at( nColumn ).strText , nTextLen -1 );
		pszText[nTextLen - 1] = '\0';
	}else{
		strcpy( pszText , m_vtrItemInfo.at( nColumn ).strText );
	}
	
	return nLen;
}

CString		CMgListCtrlBaseInfo::GetItemText( int nColumn )
{
	if( nColumn < 0 ){ return _T(""); }
	if( m_vtrItemInfo.size() <= nColumn ){ return _T(""); }

	CString		str = m_vtrItemInfo.at( nColumn ).strText ;
	return str;
}




//---------------------------------------------------------------------------------------------------------------------------
//											----- 构造函数 ------
//---------------------------------------------------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// CMgListCtrlBase

CMgListCtrlBase::CMgListCtrlBase()
{
	//
	m_clrNmlBackGround		= ::GetSysColor(COLOR_BACKGROUND) ;	//获取背景
	m_clrNmlTxtBackGround	= m_clrNmlBackGround;
	m_clrNmlTxt				= RGB( 0, 0, 0 );	//黑色
	
	m_nItemHeight			= _MGLCB_FONTNML_HEIGHT_ ;
	
	m_bDrawFocusLine		= TRUE;
	m_clrFocusLine[0]		= RGB( 0   , 0   , 0   );
	m_clrFocusLine[1]		= RGB( 255 , 255 , 255 );
	
	//
	m_clrSelBackGround		= RGB( 200, 200, 200 );	//选择时背景为灰色
	m_clrSelTxt				= RGB( 255, 255, 255 );	//文字为白色
	
	m_nGridLineState		= 0;
	
	//
	m_bYesNoShowItem		= TRUE;
	m_bYesNoOwnerData		= FALSE;	//默认不按多数据量来处理数据

	//
	m_mapListCellState.clear();
	m_mapListFullCellState.clear();
	m_mapListInfo.clear();

}

CMgListCtrlBase::~CMgListCtrlBase()
{
}


BEGIN_MESSAGE_MAP(CMgListCtrlBase, CListCtrl)
	//{{AFX_MSG_MAP(CMgListCtrlBase)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	ON_WM_MOUSEMOVE()
	ON_WM_MEASUREITEM_REFLECT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//---------------------------------------------------------------------------------------------------------------------------
//											----- 消息函数 ------
//---------------------------------------------------------------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
// CMgListCtrlBase message handlers

//--------------------------------------------------------
// WM_MEASUREITEM_REFLECT :
//--------------------------------------------------------
void	CMgListCtrlBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
	if( m_nItemHeight > 0 )
	{
		lpMeasureItemStruct->itemHeight = m_nItemHeight;
	}
}


//--------------------------------------------------------
// WM_MOUSEMOVE :
//--------------------------------------------------------
void	CMgListCtrlBase::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if( GetAsyncKeyState(VK_LBUTTON) )
	{
		//判断选择多行
		int nMark  = this->GetSelectionMark();
		int nCount = this->GetSelectedCount();
		
		//
		RECT	rtItem;
		GetItemRect( nMark , &rtItem , LVIR_BOUNDS );
		
		//
		if( rtItem.top > point.y )
		{
			int nSelCount = (rtItem.top - point.y) / m_nItemHeight ;
			if( (( point.y - rtItem.top ) % m_nItemHeight) > 0 )
			{
				nSelCount += 1;
			}
			for( int m = 0 ; m <= nSelCount ; m ++ )
			{
				if( nMark < 0 )
				{
					break;
				}
				SetSelItem( nMark );
				nMark -- ;
			}
		}else if( rtItem.bottom < point.y )
		{
			int nSelCount = ( point.y - rtItem.bottom ) / m_nItemHeight ;
			if( (( point.y - rtItem.bottom ) % m_nItemHeight) > 0 )
			{
				nSelCount += 1;
			}
			for( int m = 0 ; m <= nSelCount ; m ++ )
			{
				if( nMark < 0 )
				{
					break;
				}
				SetSelItem( nMark );
				nMark ++ ;
			}
		}
		
	}
	
	CListCtrl::OnMouseMove(nFlags, point);
}

//---------------------------------------------------------------------------------------------------------------------------
//											----- 常规函数 ------
//---------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------
//GetFullCellRect : 列表控件整行矩形
//-----------------------------------------------
int			CMgListCtrlBase::GetFullCellRect( int nItem , LPRECT lpRect )
{
	this->GetItemRect( nItem, lpRect , LVIR_BOUNDS );
	return 0;
}


//-----------------------------------------------
//GetCellRect : 列表控件单元格矩形
//-----------------------------------------------
int			CMgListCtrlBase::GetCellRect( int nItem , int nSubItem , LPRECT lpRect )
{
	CRect	rect;
	this->GetSubItemRect( nItem , nSubItem , LVIR_BOUNDS ,rect );
	
	lpRect->left = rect.left;
	lpRect->right= rect.right;
	lpRect->top	 = rect.top;
	lpRect->bottom= rect.bottom;
	
	//
	if( nSubItem == 0 )
	{
		int nW = this->GetColumnWidth( 0 );
		lpRect->right= rect.left + nW;
	}
	
	return 0;
}

//-----------------------------------------------
//SetSelItem: 设置列表控件选择项目
//-----------------------------------------------
int			CMgListCtrlBase::SetSelItem( int nIndex )
{
	if( nIndex >= 0 )
	{
		//
		this->SetSelectionMark( nIndex );
		this->SetItemState( nIndex , LVNI_SELECTED , LVNI_SELECTED );
		
		return nIndex;
	}
	
	return -1;
}


//-----------------------------------------------
//SetSelItemAndFocus: 设置列表控件选择并焦点项目
//-----------------------------------------------
int			CMgListCtrlBase::SetSelItemAndFocus( int nIndex )
{
	if( nIndex >= 0 )
	{		
		//
		this->SetSelectionMark( nIndex );
		this->SetItemState( nIndex , LVNI_SELECTED | LVNI_FOCUSED  , LVNI_SELECTED | LVNI_FOCUSED );

		return nIndex;
	}
	
	return -1;
}


//-----------------------------------------------
//SetAllTxtFont : 设置列表控件纯文本字体
//-----------------------------------------------
BOOL		CMgListCtrlBase::SetAllTxtFont( int nFontSize , char * szFontName , BOOL bRedraw )
{
	if( nFontSize <= 0 ){	return FALSE ;	}
	if( szFontName == NULL ){	return FALSE ; }
	
	m_fontAllItemFont.DeleteObject();
	
	//
	SetItemHeight( nFontSize * 78 / 72 ); //GetDeviceCaps( GetDC()->m_hDC ,LOGPIXELSY) / 72 );
	
	//
	BOOL	bResult = m_fontAllItemFont.CreateFont(	nFontSize, //这个数字就是字体大小了
								0,0,0,FW_NORMAL,FALSE,FALSE,0,
								GB2312_CHARSET,OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,
								DRAFT_QUALITY,VARIABLE_PITCH,szFontName );
	
	this->SetFont( &m_fontAllItemFont , bRedraw );
	return bResult;
}

//-----------------------------------------------
//GetAllTxtFont : 获取列表控件纯文本字体
//-----------------------------------------------
CFont *		CMgListCtrlBase::GetAllTxtFont( )
{
	return &m_fontAllItemFont;
}

//-----------------------------------------------
//ClearAllItems : 清空所有项目
//-----------------------------------------------
int			CMgListCtrlBase::ClearAllItems( )
{
	//
	m_mapListCellState.clear();
	m_mapListFullCellState.clear();

	//
	this->DeleteAllItems();
	return 0;
}


//---------------------------------------------------------------------------------------------------------------------------
//											----- 重载函数 ------
//---------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------
//DrawItem : 重画列表控件
//-----------------------------------------------
void		CMgListCtrlBase::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	DrawItemBase( lpDrawItemStruct );
}

//-----------------------------------------------
//DrawItemFocus : 重画列表控件焦点
//-----------------------------------------------
void		CMgListCtrlBase::DrawItemFocus( int nType , CDC * pDC , UINT nItemID )
{	
	DrawItemFocusBase( nType , pDC , nItemID );
}

//-----------------------------------------------
//DrawItemSelect : 重画列表控件选择
//-----------------------------------------------
void		CMgListCtrlBase::DrawItemSelect( CDC * pDC , UINT nItemID )
{
	DrawItemSelectBase( pDC , nItemID );
}

//-----------------------------------------------
//DrawCellText : 重画列表控件单元格文本
//-----------------------------------------------
void		CMgListCtrlBase::DrawCellText( CDC * pDC , UINT nItemID , int nColumn ,LPRECT pRect  )
{
	DrawCellTextBase( pDC , nItemID , nColumn ,pRect );
}

//-----------------------------------------------
//DrawCellState : 重画列表控件单元格状态
//-----------------------------------------------
void		CMgListCtrlBase::DrawCellState( CDC * pDC , UINT nItemID , int nColumn  ,LPRECT pRect )
{
	DrawCellStateBase( pDC , nItemID , nColumn , pRect );
}


//-----------------------------------------------
//DrawCustomInfo : 重画列表控件自定义
//-----------------------------------------------
void		CMgListCtrlBase::DrawCustomInfo( CDC * pDC , UINT nItemID )
{
	//该函数为虚函数,是用来绘画自定义数据,改函数需要子类化重载:
}

//---------------------------------------------------------------------------------------------------------------------------
//											----- 重绘基础函数 ------
//---------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------
//DrawItemBase : 重画列表控件基本函数
//-----------------------------------------------
void		CMgListCtrlBase::DrawItemBase(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	if( !lpDrawItemStruct ){ return; }
	if( !m_bYesNoShowItem ){ return; }
	
	//
	CDC *	pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	int nSaveDC = pDC->SaveDC();
	
	//
	if( m_nItemHeight <= (lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top) )
	{
		m_nItemHeight = lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top;
	}
	
	//
	LV_ITEM lvi;
	lvi.mask = LVIF_IMAGE | LVIF_STATE;
	lvi.iItem = lpDrawItemStruct->itemID;
	lvi.iSubItem = 0;
	lvi.stateMask = 0xFFFF;		// get all state flags
	GetItem(&lvi);
	
	//
	_enum_LIS_		lis = _E_LIS_Normal_; 
	//
	switch( lvi.state )
	{
	case LVIS_FOCUSED : //焦点
		{
			lis = _E_LIS_Focus_;
			break;
		}
	case LVIS_SELECTED: //选择
		{	
			lis = _E_LIS_Select_;
			break;
		}
	case LVIS_FOCUSED | LVIS_SELECTED : //焦点并选择
		{	
			lis = _E_LIS_SelAndFocus_;
			break;
		}
	default:
		{
			lis = _E_LIS_Default_;
			break;
		}
	}
	
	//
	DrawItemMainBase( pDC , lpDrawItemStruct->itemID , lis );
	
	//
	pDC->RestoreDC( nSaveDC );
}

//-----------------------------------------------
//DrawItemMainBase : 重画列表控件主要基本函数
//-----------------------------------------------
void	CMgListCtrlBase::DrawItemMainBase( CDC * pDC , UINT nItemID , int nType )
{
	//重画背景覆盖残留:
	RECT	rtItem;
	GetFullCellRect( nItemID , &rtItem );
	pDC->FillSolidRect( &rtItem , m_clrNmlBackGround );
	
	//画当前状态:
	if( nType == _E_LIS_Focus_ )
	{
		DrawItemFocus( 0 , pDC , nItemID );
	}
	if( nType == _E_LIS_Select_ )
	{
		DrawItemSelect( pDC , nItemID );
	}
	if( nType == _E_LIS_SelAndFocus_ )
	{
		DrawItemSelect( pDC , nItemID );
		DrawItemFocus( 1 , pDC , nItemID );
	}
	
	//画网格线:
	DrawGridLineBase( pDC , nItemID );
	
	//画单元格:
	DrawCellBase( pDC , nItemID );
	
	//自定义绘画:
	DrawCustomInfo( pDC , nItemID );
}

//-----------------------------------------------
//DrawItemFocusBase : 重画列表控件焦点基本函数,
//分选择和非选择焦点
//-----------------------------------------------
int		CMgListCtrlBase::DrawItemFocusBase( int nType , CDC * pDC , UINT nItemID )
{
	if( pDC == NULL ){ return -1; }
	if( m_bDrawFocusLine == FALSE ){ return 0 ; }
	
	//
	RECT	rtItem;
	GetFullCellRect( nItemID , &rtItem );
	
	//画焦点框
	CPen         penNew;
	CPen		*penOld = NULL;
	CGdiObject  *pOldBrush = NULL;
	
	if( nType == 1 )
	{
		//
		penNew.CreatePen( PS_DOT, 0 , m_clrFocusLine[1]  ); //创建白色的....线:
		penOld = pDC->SelectObject( &penNew );
		pOldBrush=pDC->SelectStockObject( NULL_BRUSH );
		
		//
		pDC->Rectangle( &rtItem );
		
		//
		pDC->SelectObject( penOld );
		pDC->SelectObject( pOldBrush );
		penNew.DeleteObject();
	}else{
		penNew.CreatePen( PS_DOT, 0 , m_clrFocusLine[0]  ); //创建白色的....线:
		penOld = pDC->SelectObject( &penNew );
		pOldBrush=pDC->SelectStockObject( NULL_BRUSH );
		
		//
		pDC->Rectangle( &rtItem );
		
		//
		pDC->SelectObject( penOld );
		pDC->SelectObject( pOldBrush );
		penNew.DeleteObject();
	}
	
	return 1;
}


//-----------------------------------------------
//DrawItemSelectBase : 重画列表控件选择基本函数
//-----------------------------------------------
int		CMgListCtrlBase::DrawItemSelectBase( CDC * pDC , UINT nItemID )
{
	if( pDC == NULL ){ return -1; }
	
	RECT	rtItem;
	this->GetFullCellRect( nItemID , &rtItem );
	pDC->FillSolidRect( &rtItem , m_clrSelBackGround );
	
	return 1;
}


//-----------------------------------------------
//DrawGridLineBase : 重画列表控件网格线基本函数
//-----------------------------------------------
int		CMgListCtrlBase::DrawGridLineBase( CDC * pDC , UINT nItemID )
{
	if( m_nGridLineState == _E_LGL_VLine_ || m_nGridLineState == _E_LGL_HVLine_ )
	{
		RECT	rtClient;
		this->GetClientRect( &rtClient );
		
		CHeaderCtrl	*pHeader = this->GetHeaderCtrl();
		int nCount = pHeader->GetItemCount(); 
		
		CPen         penNew;
		CPen		*penOld = NULL;
		CGdiObject  *pOldBrush = NULL;
		penNew.CreatePen( PS_SOLID, 1 , m_clrGridLine[0]  ); 
		penOld = pDC->SelectObject( &penNew );
		pOldBrush=pDC->SelectStockObject( NULL_BRUSH );
		
		for( int n = 0 ; n < ( nCount - 1 ); n ++ )
		{
			RECT	rect;
			this->GetCellRect( nItemID , n , &rect );
			pDC->MoveTo( rect.right - 1, rtClient.top );
			pDC->LineTo( rect.right - 1, rtClient.bottom );
		}
		
		//
		pDC->SelectObject( penOld );
		pDC->SelectObject( pOldBrush );
		penNew.DeleteObject();
	}
	
	if( m_nGridLineState == _E_LGL_HLine_ || m_nGridLineState == _E_LGL_HVLine_ )
	{
		CPen         penNew;
		CPen		*penOld = NULL;
		CGdiObject  *pOldBrush = NULL;
		penNew.CreatePen( PS_SOLID, 1 , m_clrGridLine[1]  ); 
		penOld = pDC->SelectObject( &penNew );
		pOldBrush=pDC->SelectStockObject( NULL_BRUSH );
		
		RECT	rect;
		this->GetFullCellRect( nItemID , &rect );
		pDC->MoveTo( rect.left, rect.bottom - 1 );
		pDC->LineTo( rect.right,rect.bottom - 1 );
		
		//
		pDC->SelectObject( penOld );
		pDC->SelectObject( pOldBrush );
		penNew.DeleteObject();
	}
	
	
	return 1;
}

//-----------------------------------------------
//DrawCellBase : 重画列表控件单元格基本函数
//-----------------------------------------------
int		CMgListCtrlBase::DrawCellBase( CDC * pDC , UINT nItemID )
{
	CHeaderCtrl		*pheader	= this->GetHeaderCtrl();
	int				nCount		= pheader->GetItemCount();
	
	COLORREF	clrOldTxt = pDC->GetTextColor();
	
	//画整行:
	std::map<int,_T_LCS_>::iterator	itr1 = m_mapListFullCellState.begin();
	std::map<int,_T_LCS_>::iterator	itr2 = m_mapListFullCellState.end();
	for( ; itr1 != itr2 ; itr1 ++ )
	{
		if( itr1->second.nItem == nItemID )
		{			
			RECT	rect;
			this->GetFullCellRect( nItemID , &rect );
			pDC->FillSolidRect( &rect , itr1->second.clrBk );
			pDC->SetTextColor( itr1->second.clrTxt );
		}
	}
	
	//	
	for( int n = 0 ; n < nCount ; n ++ )
	{
		COLORREF	clrOld = pDC->GetTextColor( );
		
		RECT	rect;
		this->GetCellRect( nItemID , n , &rect );
		DrawCellState( pDC , nItemID , n , &rect );

		if( m_bYesNoOwnerData ){ vl_DrawCellText( pDC , nItemID , n , &rect ); }
		else{ DrawCellText( pDC , nItemID , n , &rect ); }
		
		//覆盖一下:
		pDC->SetTextColor( clrOld );
	}
	
	//
	pDC->SetTextColor( clrOldTxt );
	
	return 1;
}



//-----------------------------------------------
//DrawCellTextBase : 重画列表控件单元格文本基本函数
//-----------------------------------------------
int		CMgListCtrlBase::DrawCellTextBase( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect )
{
	RECT	rtItem;
	rtItem.left	= pRect->left;
	rtItem.right= pRect->right;
	rtItem.top	= pRect->top;
	rtItem.bottom=pRect->bottom;
	
	LV_COLUMN	_col;
	_col.mask	= LVCF_FMT;
	this->GetColumn( nColumn , &_col );
	
	COLORREF	clrOldBk = pDC->GetBkColor();
	COLORREF	clrOldTxt= pDC->GetTextColor();
	
	
	//默认处理
	switch( _col.fmt )
	{
	case LVCFMT_LEFT | 0x4000 :
		{		
			rtItem.left += 5;	
			pDC->DrawText( this->GetItemText(nItemID,nColumn) , &rtItem , DT_LEFT|DT_SINGLELINE );
			break;
		}
	case LVCFMT_CENTER | 0x4000 :
		{
			pDC->DrawText( this->GetItemText(nItemID,nColumn) , &rtItem , DT_CENTER|DT_SINGLELINE );
			break;
		}
	case LVCFMT_RIGHT | 0x4000 :
		{
			rtItem.right -= 5;
			pDC->DrawText( this->GetItemText(nItemID,nColumn) , &rtItem , DT_RIGHT|DT_SINGLELINE );
			break;
		}
	default:
		{		
			rtItem.left += 5;			
			pDC->DrawText( this->GetItemText(nItemID,nColumn) , &rtItem , DT_LEFT|DT_SINGLELINE );
			break;
		}
	}
	
	//
	pDC->SetBkColor( clrOldBk );
	pDC->SetTextColor( clrOldTxt );
	
	return 1;
}


//-----------------------------------------------
//DrawCellStateBase : 重画列表控件单元格状态基本函数
//-----------------------------------------------
int		CMgListCtrlBase::DrawCellStateBase( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect )
{
	std::map<int,_T_LCS_>::iterator	itr1 = m_mapListCellState.begin();
	std::map<int,_T_LCS_>::iterator	itr2 = m_mapListCellState.end();
	for( ; itr1 != itr2 ; itr1 ++ )
	{
		if( itr1->second.nItem == nItemID && itr1->second.nSubItem == nColumn )
		{
			pDC->FillSolidRect( pRect , itr1->second.clrBk );
			pDC->SetTextColor( itr1->second.clrTxt );
		}
	}
	return 1;
}

//---------------------------------------------------------------------------------------------------------------------------
//											----- 基本设置类函数 ------
//---------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------
//SetStyle : 设置列表控件风格
//-----------------------------------------------
int		CMgListCtrlBase::SetStyle( _enum_LCS_	lcs )
{
	this->SetStyle( (DWORD)lcs );
	return 0;
}

int		CMgListCtrlBase::SetStyle( DWORD dwStyle  )
{
	this->ModifyStyle( NULL , dwStyle  );
	return 0;
}

//-----------------------------------------------
//SetExStyle : 设置列表控件扩展风格
//-----------------------------------------------
int		CMgListCtrlBase::SetExStyle( DWORD dwStyle )
{
	return this->SetExtendedStyle( this->GetExtendedStyle() | dwStyle );
}


//-----------------------------------------------
//SetShowItem : 是否显示项目(可以选择否,等添加完成项目,再显示,提高速率.)
//-----------------------------------------------
BOOL	CMgListCtrlBase::SetShowItem( BOOL bShow )
{
	BOOL	bResult = m_bYesNoShowItem;
	m_bYesNoShowItem = bShow;
	return bResult;
}

//-----------------------------------------------
//SetOwnerDraw : 设置列表控件是否重画
//-----------------------------------------------
int		CMgListCtrlBase::SetOwnerDraw( BOOL bDraw )
{
	if( bDraw == TRUE )
	{
		this->ModifyStyle( NULL , LVS_OWNERDRAWFIXED );
	}
	
	return 0;
}

//-----------------------------------------------
//SetOwnerData : 设置列表控件是否按大数据量处理数据:
//-----------------------------------------------
int		CMgListCtrlBase::SetOwnerData( BOOL bOwnerData )
{
	if( bOwnerData == TRUE )
	{
		//无法开启该属性.
		this->ModifyStyle( NULL , LVS_OWNERDATA );
		m_bYesNoOwnerData = TRUE;
	}
	
	return 0;
}

//-----------------------------------------------
//SetShowFocus : 是否显示焦点线框
//-----------------------------------------------
BOOL	CMgListCtrlBase::SetShowFocus( BOOL bShow , COLORREF	clrNml , COLORREF clrSel )
{
	//
	m_clrFocusLine[0] = clrNml;
	m_clrFocusLine[1] = clrSel;
	
	BOOL bResult = m_bDrawFocusLine ;
	m_bDrawFocusLine = bShow;
	return bResult;
}

//-----------------------------------------------
//SetGridLineState : 设置网格线
//-----------------------------------------------
void	CMgListCtrlBase::SetGridLineState( int	nMgState , int nNmlState , COLORREF clrV , COLORREF clrH )
{
	m_clrGridLine[0] = clrV;
	m_clrGridLine[1] = clrH;
	
	if( nMgState >= 0 ){ nNmlState = -1; m_nGridLineState = nMgState ; }
	if( nNmlState >= 0 )
	{ 
		nMgState = -1; 
		m_nGridLineState = 0;
		
		SetExStyle( this->GetExtendedStyle() | LVS_EX_GRIDLINES );
	}
	
}


//-----------------------------------------------
//SetItemHeight : 设置列表控件项目高度
//-----------------------------------------------
void	CMgListCtrlBase::SetItemHeight( int nHeight )
{
	m_nItemHeight = nHeight;
	
	CRect rcWin;
	GetWindowRect(&rcWin);
	WINDOWPOS wp;
	wp.hwnd = m_hWnd;
	wp.cx = rcWin.Width();
	wp.cy = rcWin.Height();
	wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
	SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
}



//---------------------------------------------------------------------------------------------------------------------------
//											----- 颜色设置类函数 ------
//---------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------
//SetNmlColor : 设置列表控件默认背景
//-----------------------------------------------
BOOL		CMgListCtrlBase::SetNmlBkColor( COLORREF  color )
{
	m_clrNmlBackGround	= color;
	return this->SetBkColor( m_clrNmlBackGround );
}

COLORREF	CMgListCtrlBase::GetNmlBkColor( )
{
	m_clrNmlBackGround = this->GetBkColor();
	return m_clrNmlBackGround;
}

//-----------------------------------------------
//SetTxtBkColor : 设置列表控件纯文本背景
//-----------------------------------------------
BOOL		CMgListCtrlBase::SetNmlTxtBkColor( COLORREF	color )
{
	m_clrNmlTxtBackGround	= color;
	return this->SetTextBkColor( m_clrNmlTxtBackGround );
}

COLORREF	CMgListCtrlBase::GetNmlTxtBkColor( )
{
	m_clrNmlTxtBackGround = this->GetTextBkColor();
	return m_clrNmlTxtBackGround;
}


//-----------------------------------------------
//SetTxtColor : 设置列表控件纯文本颜色
//-----------------------------------------------
BOOL		CMgListCtrlBase::SetNmlTxtColor( COLORREF	color )
{
	m_clrNmlTxt	= color;
	return this->SetTextColor( m_clrNmlTxt );
}

COLORREF	CMgListCtrlBase::GetNmlTxtColor( )
{
	m_clrNmlTxt = this->GetTextColor();
	return m_clrNmlTxt;
}

//-----------------------------------------------
//SetSelBkColor : 设置列表控件选择时背景
//-----------------------------------------------
BOOL		CMgListCtrlBase::SetSelBkColor( COLORREF	color )
{
	m_clrSelBackGround = color;
	return TRUE;
}

COLORREF	CMgListCtrlBase::GetSelBkColor( )
{
	return m_clrSelBackGround;
}


//-----------------------------------------------
//SetSelTxtColor : 设置列表控件选择时文本颜色
//-----------------------------------------------
BOOL		CMgListCtrlBase::SetSelTxtColor( COLORREF	color )
{
	m_clrSelTxt = color ;
	return TRUE;
}

COLORREF	CMgListCtrlBase::GetSelTxtColor( )
{
	return m_clrSelTxt;
}


//---------------------------------------------------------------------------------------------------------------------------
//											----- 大数据项目类函数 ------
//---------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------
//vl_DrawCellText : 重画列表控件单元格文本
//-----------------------------------------------
void		CMgListCtrlBase::vl_DrawCellText( CDC * pDC , UINT nItemID , int nColumn ,LPRECT pRect  )
{
	vl_DrawCellTextBase( pDC , nItemID , nColumn ,pRect );
}

//-----------------------------------------------
//DrawCellTextBase : 重画列表控件单元格文本基本函数
//-----------------------------------------------
int		CMgListCtrlBase::vl_DrawCellTextBase( CDC * pDC , UINT nItemID , int nColumn , LPRECT pRect )
{
	RECT	rtItem;
	rtItem.left	= pRect->left;
	rtItem.right= pRect->right;
	rtItem.top	= pRect->top;
	rtItem.bottom=pRect->bottom;
	
	LV_COLUMN	_col;
	_col.mask	= LVCF_FMT;
	this->GetColumn( nColumn , &_col );
	
	COLORREF	clrOldBk = pDC->GetBkColor();
	COLORREF	clrOldTxt= pDC->GetTextColor();
	
	
	//默认处理
	switch( _col.fmt )
	{
	case LVCFMT_LEFT | 0x4000 :
		{		
			rtItem.left += 5;	
			pDC->DrawText( m_mapListInfo[nItemID].GetItemText(nColumn) , &rtItem , DT_LEFT|DT_SINGLELINE );
			break;
		}
	case LVCFMT_CENTER | 0x4000 :
		{
			pDC->DrawText( m_mapListInfo[nItemID].GetItemText(nColumn) , &rtItem , DT_CENTER|DT_SINGLELINE );
			break;
		}
	case LVCFMT_RIGHT | 0x4000 :
		{
			rtItem.right -= 5;
			pDC->DrawText( m_mapListInfo[nItemID].GetItemText(nColumn) , &rtItem , DT_RIGHT|DT_SINGLELINE );
			break;
		}
	default:
		{		
			rtItem.left += 5;			
			pDC->DrawText( m_mapListInfo[nItemID].GetItemText(nColumn) , &rtItem , DT_LEFT|DT_SINGLELINE );
			break;
		}
	}
	
	//
	pDC->SetBkColor( clrOldBk );
	pDC->SetTextColor( clrOldTxt );
	
	return 1;
}

//-----------------------------------------------
//vl_InsertItem : 向列表控件插入项目
//-----------------------------------------------
int		CMgListCtrlBase::vl_InsertItem( int nItem , LPCTSTR	strItem , BOOL bUpdate )
{
	CMgListCtrlBaseInfo	info;
	info.SetIndex( nItem );
	info.SetItemText( 0 , strItem );
	
	int	nSize = m_mapListInfo.size();
	for( int n = nSize - 1 ; n >= nItem ; n -- )
	{
		m_mapListInfo[n].SetIndex( m_mapListInfo[n].GetIndex() + 1 );
		m_mapListInfo[n+1] = m_mapListInfo[n];
	}
	m_mapListInfo.erase( nItem );
	m_mapListInfo.insert( std::pair<int,CMgListCtrlBaseInfo>( nItem , info ) );

	/*
	SCROLLINFO	si;
	this->GetScrollInfo( SB_VERT , &si );
	si.nMax = nItem;
	this->SetScrollInfo( SB_VERT , &si );
	*/

	if( bUpdate == TRUE ){ this->SetItemCount( m_mapListInfo.size() ); }
	//this->Invalidate();

	return m_mapListInfo.size() ;
}


//-----------------------------------------------
//vl_DeleteItem : 删除列表控件指定项目
//-----------------------------------------------
int		CMgListCtrlBase::vl_DeleteItem( int nItem )
{
	for( int n = nItem ; n < m_mapListInfo.size() - 1 ; n ++ )
	{
		m_mapListInfo[n] = m_mapListInfo[n+1];
	}
	m_mapListInfo.erase( m_mapListInfo.size() - 1 );
	this->SetItemCount( m_mapListInfo.size() - 1 );

	return this->GetItemCount() - 1;
}

int		CMgListCtrlBase::vl_DeleteAllItems( )
{
	m_mapListCellState.clear();
	m_mapListFullCellState.clear();
	m_mapListInfo.clear();

	this->SetItemCount( 0 );
	return 0;
}

//-----------------------------------------------
//vl_SetItemText : 设置列表控件指定项目文本
//-----------------------------------------------
int		CMgListCtrlBase::vl_SetItemText( int nItem, int nColumn , LPCTSTR pszItem )
{
	return m_mapListInfo[nItem].SetItemText( nColumn , pszItem );
}

//-----------------------------------------------
//vl_GetItemText : 获取列表控件指定项目文本
//-----------------------------------------------
int		CMgListCtrlBase::vl_GetItemText( int nItem , int nColumn , LPTSTR pszItem , int nItemLen )
{
	return m_mapListInfo[nItem].GetItemText( nColumn , pszItem , nItemLen );
}


CString CMgListCtrlBase::vl_GetItemText( int nItem , int nColumn )
{
	return m_mapListInfo[nItem].GetItemText( nColumn );
}




[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (14)
雪    币: 1657
活跃值: (291)
能力值: ( LV9,RANK:610 )
在线值:
发帖
回帖
粉丝
2
1楼太高,说明贴2楼。
单元格颜色可以设置,正行颜色也可以设置,焦点颜色和是否出现也可以设置,根据喜欢可以设置为网格线为横或纵或横纵,网格线横纵颜色也可以分开设置。
这此新加了多行处理,需要在创建控件的时候选上OWNERDATA属性。
使用vl开头的函数就可以了,无需重载任何消息,我已经画好了。
整体使用vector来存储数据,但是由于vector速度快,提高了速度,占用内存大了点。

新加了个自定义函数,方便大家拿去自己加东西,加完后,根据情况更新一下数据。
比如像OD里的连接线就可以加在这个函数里。

说明结束,给需要的人一个方便,如果觉得不好,就路过好了

如有与本版不否,请斑竹移一下,谢谢.
2009-7-29 16:09
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
3
Code放附件里面多好.整贴 贴代码,拉的好长啊~~~
2009-7-29 17:34
0
雪    币: 3226
活跃值: (2868)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
  提两个问题.....大量插入数据速度如何? 绘画有设定重绘的范围么?  楼主能发个效果图最好了..........微软給的半成品的东西就是累人........支持楼主改进.....
2009-7-30 10:10
0
雪    币: 151
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
好,支持一个
2009-7-31 12:13
0
雪    币: 151
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
打包方便大家下载
上传的附件:
2009-7-31 12:20
0
雪    币: 1657
活跃值: (291)
能力值: ( LV9,RANK:610 )
在线值:
发帖
回帖
粉丝
7
速度比较快插入50W行我电脑就几秒。。。
我电脑不好,电脑好的速度会更快点,插入数据的时候把最后一个项目设置为FALSE,最后插入完了,再设置插入行。。。
不多说了闪了。。
代码给出来了自己看看,效果就不用贴了。。
把OD打开,和OD几乎差不多,我是按OD做的.
2009-7-31 15:15
0
雪    币: 223
活跃值: (10)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
8
给个效果图看看.
2009-7-31 17:56
0
雪    币: 243
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
scm
9
能不能放个实例工程,最好能支持显示树形。O(∩_∩)O~
2009-8-5 08:39
0
雪    币: 227
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
以为汇编写的呢。。。。。
2009-8-5 09:14
0
雪    币: 3226
活跃值: (2868)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
水平不行。。做了个简单的测试。。楼主帮看下错哪了。。。

BOOL CVirtualTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码

	m_MgListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	m_MgListCtrl.InsertColumn(0,"Test",LVCFMT_LEFT,150);
	m_MgListCtrl.m_bYesNoOwnerData = 1;


	return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
}



void CVirtualTestDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	CMgListCtrlBaseInfo cmg;
	cmg.SetIndex(0);
	cmg.SetItemText(0,"Test");

	m_MgListCtrl.m_mapListInfo.insert(std::map<int, CMgListCtrlBaseInfo>::value_type(1,cmg));
	m_MgListCtrl.SetItemCount(m_MgListCtrl.m_mapListInfo.size());
}


控件 已设置 OWERDATA 属性  Report
2009-8-6 16:12
0
雪    币: 3226
活跃值: (2868)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
折腾不出来。。。楼主有空发个 demo 工程吧。。。。在 owner data 属性下 怎么改变 颜色一直没弄好。。。。
2009-9-10 00:07
0
雪    币: 952
活跃值: (1821)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
试了下``不会用````````
2009-9-10 11:02
0
雪    币: 20
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
好东西 这么长建议用附件
2009-9-10 12:39
0
雪    币: 229
活跃值: (498)
能力值: ( LV10,RANK:170 )
在线值:
发帖
回帖
粉丝
15


用了下..我只能弄成这样..感觉有些函数没有实现....
不过还是不错....
上传的附件:
2009-9-10 13:18
0
游客
登录 | 注册 方可回帖
返回
//