void CListCtrlCl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
TCHAR lpBuffer[256];
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = lpDrawItemStruct->itemID ;
lvi.iSubItem = 0;
lvi.pszText = lpBuffer ;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
LV_COLUMN lvc, lvcprev ;
::ZeroMemory(&lvc, sizeof(lvc));
::ZeroMemory(&lvcprev, sizeof(lvcprev));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvcprev.mask = LVCF_WIDTH | LVCF_FMT;
CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rtClient;
GetClientRect(&rtClient);
CRect rcItem;
for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
{
if ( nCol > 0 )
{
GetColumn(nCol-1, &lvcprev) ;
lpDrawItemStruct->rcItem.left += lvcprev.cx ;
lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left;
}
if (!GetSubItemRect(lpDrawItemStruct->itemID,nCol,LVIR_LABEL,rcItem))
continue;
::ZeroMemory(&lvi, sizeof(lvi));
lvi.iItem = lpDrawItemStruct->itemID;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iSubItem = nCol;
lvi.pszText = lpBuffer;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
CRect rcTemp;
rcTemp = rcItem;
if (nCol==0)
{
rcTemp.left -=2;
}
if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
pDC->FillSolidRect(&rcTemp, GetSysColor(COLOR_HIGHLIGHT)) ;
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
}
else
{
COLORREF color;
color = GetBkColor();
pDC->FillSolidRect(rcTemp,color);
if (FindColColor(nCol,color))
{
pDC->FillSolidRect(rcTemp,color);
}
if (FindItemColor(nCol,lpDrawItemStruct->itemID,color))
{
pDC->FillSolidRect(rcTemp,color);
}
if(1 == (lpDrawItemStruct->itemID % 2))
{
pDC->FillSolidRect(rcTemp,COLORREF(0x00ffffff));
}else
{
pDC->FillSolidRect(rcTemp,COLORREF(0x00EEEEEE));
}
//pDC->SetTextColor(m_color);
}
pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));
UINT uFormat= DT_CENTER ;
if (m_Header.m_Format[nCol]=='0')
{
uFormat = DT_LEFT;
}
else if (m_Header.m_Format[nCol]=='1')
{
uFormat = DT_CENTER;
}
else if (m_Header.m_Format[nCol]=='2')
{
uFormat = DT_RIGHT;
}
uFormat = (DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->SetTextColor(m_color);
COLORREF color;
if (FindColTextColor(nCol,color))
{
pDC->SetTextColor(color);
}
if (FindItemTextColor(nCol,lpDrawItemStruct->itemID,color))
{
pDC->SetTextColor(color);
}
CFont nFont ,* nOldFont;
nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体
nOldFont = pDC->SelectObject(&nFont);
DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&rcItem, uFormat) ;
pDC->SelectStockObject(SYSTEM_FONT) ;
// 画圆
if (nCol == 4)
{
Graphics gh(lpDrawItemStruct->hDC);
if('0' == lpBuffer[0])
{
gh.DrawImage(g_pBmpGray,rcItem.left+(rcItem.right-rcItem.left)/2-8,rcItem.top+(rcItem.bottom-rcItem.top)/2-8,16,16);
}else
{
gh.DrawImage(g_pBmpGree,rcItem.left+(rcItem.right-rcItem.left)/2-8,rcItem.top+(rcItem.bottom-rcItem.top)/2-8,16,16);
}
}
}
}