⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editlist.cpp

📁 用Visual c++.net开发的图书管理系统
💻 CPP
字号:
#include "stdafx.h"
#include "EditList.h"
#include ".\editlist.h"


// CEditList

IMPLEMENT_DYNAMIC(CEditList, CListCtrl)
CEditList::CEditList()
{
}

CEditList::~CEditList()
{
}


BEGIN_MESSAGE_MAP(CEditList, CListCtrl)
	ON_NOTIFY_REFLECT(NM_CLICK, OnNMClick)
	ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
END_MESSAGE_MAP()


void CEditList::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
{
	NM_LISTVIEW *pListView = reinterpret_cast<NM_LISTVIEW*>(pNMHDR);

	STYLEMAP::iterator iter = m_mapStyle.find( std::make_pair<int, int>( pListView->iItem, pListView->iSubItem ) );
	if ( iter == m_mapStyle.end() )
		return;
	int nStyle = (*iter).second.nStyle;
	LPVOID pData = (*iter).second.pData;
	if ( nStyle == EL_COMBOBOX )
	{
		CItemComboBox *pBox = new CItemComboBox( this, pListView->iItem, pListView->iSubItem, reinterpret_cast<CMapStringToString*>(pData) );
	}
	else if ( nStyle == EL_EDIT )
	{
		CItemEdit *pEdit = new CItemEdit( this, pListView->iItem, pListView->iSubItem );
	}
}

int CEditList::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText, int nStyle/* = 0*/, LPVOID pData/* = 0*/)
{
	if ( nStyle != EL_NONE )
	{
		EXTSTYLE extStyle;
		extStyle.nStyle = nStyle;
		extStyle.bEdited = FALSE;
		extStyle.clrText = RGB(0,0,0);
		extStyle.clrBackground = RGB(255,255,255);
		extStyle.pData = pData;// user need keep the pointer valid through list living span
		m_mapStyle[std::make_pair<int,int>(nItem, nSubItem)] = extStyle;
	}
	return CListCtrl::SetItemText( nItem, nSubItem, lpszText );
}

void CEditList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
	*pResult = CDRF_DODEFAULT;
	if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
	{
		*pResult = CDRF_NOTIFYITEMDRAW;
	}
	else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
	{
		// This is the notification message for an item.  We'll request
		// notifications before each subitem's prepaint stage.

		*pResult = CDRF_NOTIFYSUBITEMDRAW;
	}
	else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
	{
		STYLEMAP::iterator iter = m_mapStyle.find( std::make_pair<int, int>( (int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem ) );
		if ( iter == m_mapStyle.end() )
		{
			pLVCD->clrText = RGB(0,0,0);
			pLVCD->clrTextBk = RGB(255,255,255);
		}
		else
		{
			// Store the colors back in the NMLVCUSTOMDRAW struct.
			pLVCD->clrText = (*iter).second.clrText;
			pLVCD->clrTextBk = (*iter).second.clrBackground;
		}

		// Tell Windows to paint the control itself.
		*pResult = CDRF_DODEFAULT;
	}
}

void CEditList::SetItemColor(int nItem, int nSubItem, COLORREF clrText, COLORREF clrBackground)
{
	STYLEMAP::iterator iter = m_mapStyle.find( std::make_pair<int, int>( nItem, nSubItem ) );
	if ( iter == m_mapStyle.end() )
		return;
	(*iter).second.clrText = clrText;
	(*iter).second.clrBackground = clrBackground;
}

void CEditList::PreSubclassWindow()
{
	SetExtendedStyle( GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
	ModifyStyle(0, LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP);

	CListCtrl::PreSubclassWindow();
}

void CEditList::SetEditedFlag(int nItem, int nSubItem, BOOL bEdited)
{
	STYLEMAP::iterator iter = m_mapStyle.find( std::make_pair<int, int>( nItem, nSubItem ) );
	if ( iter == m_mapStyle.end() )
		return;
	(*iter).second.bEdited = bEdited;
}

BOOL CEditList::GetItemEditedFlag(int nItem, int nSubItem)
{
	STYLEMAP::iterator iter = m_mapStyle.find( std::make_pair<int, int>( nItem, nSubItem ) );
	if ( iter == m_mapStyle.end() )
		return FALSE;
	return (*iter).second.bEdited;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -