【VC开源代码栏目提醒】:网学会员VC开源代码为您提供LISTEDITVIEW.CPP参考,解决您在LISTEDITVIEW.CPP学习中工作中的难题,参考学习。
// ListEditView.cpp : implementation of the CListEditView class
//
// Reg Anderson June 5 1998.
#include "stdafx.h"
#include "ListEditView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLVEdit
BEGIN_MESSAGE_MAP(CLVEdit, CEdit)
//{{AFX_MSG_MAP(CLVEdit)
ON_WM_WINDOWPOSCHANGING()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CLVEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
lpwndpos->x=m_x;
lpwndpos->y=m_y;
CEdit::OnWindowPosChanging(lpwndpos);
}
/////////////////////////////////////////////////////////////////////////////
// CListEditView
IMPLEMENT_DYNCREATE(CListEditView, CListView)
BEGIN_MESSAGE_MAP(CListEditView, CListView)
//{{AFX_MSG_MAP(CListEditView)
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
ON_NOTIFY_REFLECT(LVN_ENDLABELEDIT, OnEndLabelEdit)
ON_NOTIFY_REFLECT(LVN_BEGINLABELEDIT, OnBeginLabelEdit)
//}}AFX_MSG_MAP
// Standard printing commands
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListEditView construction/destruction
CListEditView::CListEditView()
{
m_cx=0;
m_nEdit=-1;
}
CListEditView::~CListEditView()
{
}
BOOL CListEditView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style|=LVS_REPORT|
LVS_SINGLESEL|
LVS_SHOWSELALWAYS|
LVS_EDITLABELS|
LVS_OWNERDRAWFIXED;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CListEditView diagnostics
#ifdef _DEBUG
void CListEditView::AssertValid() const
{
CListView::AssertValid();
}
void CListEditView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CListEditView methods
LPCTSTR CListEditView::MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen)
{
static _TCHAR szLVStaticTemp[1024];
static const _TCHAR szThreeDots[]=_T("...");
int nStringLen=lstrlen(lpszLong);
if(nStringLen==0 || pDC->GetTextExtent(lpszLong,nStringLen).cx<=nColumnLen)
return(lpszLong);
lstrcpy(szLVStaticTemp,lpszLong);
int nAddLen=pDC->GetTextExtent(szThreeDots,sizeof(szThreeDots)).cx;
for(int i=nStringLen-1; i>0; i--)
{
szLVStaticTemp[i]=0;
if(pDC->GetTextExtent(szLVStaticTemp,i).cx+nAddLen<=nColumnLen)
break;
}
lstrcat(szLVStaticTemp,szThreeDots);
return(szLVStaticTemp);
}
#define OFFSET_FIRST 2
#define OFFSET_OTHER 6
void CListEditView::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
int nItem=lpDIS->itemID;
CDC* pDC=CDC::FromHandle(lpDIS->hDC);
CRect rcAllLabels;
GetListCtrl().GetItemRect(nItem,rcAllLabels,LVIR_BOUNDS);
CRect rcItem;
GetListCtrl().GetItemRect(nItem,rcItem,LVIR_LABEL);
rcAllLabels.left=rcItem.left;
if(rcAllLabels.right<m_cx)
rcAllLabels.right=m_cx-2;
LV_ITEM lvi;
lvi.mask=LVIF_STATE;
lvi.iItem=nItem;
lvi.iSubItem=0;
lvi.stateMask=0xFFFF;
GetListCtrl().GetItem(&lvi);
BOOL bFocus=(GetFocus()==this);
BOOL bSelected=(lvi.state&LVIS_SELECTED &&
(GetStyle()&LVS_SHOWSELALWAYS));
bSelected=bSelected||(lvi.state&LVIS_DROPHILITED);
int nOldDCMode=pDC->SaveDC();
if(bSelected && m_nEdit==-1)
{
pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
pDC->FillRect(rcAllLabels,&