CListCtrlCl::DrawItem


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);
}
}
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可修改颜色的一个CListCtrlCl类 部分函数如下所示 public: 行高 int m nRowHeight; int InsertColumn int nCol LPCTSTR lpszColumnHeading int nFormat LVCFMT LEFT int nWidth 1 int nSubItem 1 ; public: Gradient 渐变系数 立体背景用 不用渐变设为0 void SetHeaderBKColor int R int G int B int Gradient ; public: 设置表头高度 void SetHeaderHeight float Height ; CPtrList m ptrListCol; 保存列颜色 CPtrList m ptrListItem; 保存Item颜色表 CPtrList m colTextColor; 保存列字体颜色 CPtrList m ItemTextColor; 保存单元格字体颜色 bool FindColColor int col COLORREF &color ; 查找列颜色 bool FindItemColor int col int row COLORREF &color ; bool FindColTextColor int col COLORREF &color ; 查找列字体颜色 bool FindItemTextColor int col int row COLORREF &color ; void SetColColor int col COLORREF color ; 设置列颜色 void SetItemColor int col int row COLORREF color ; 设置Item颜色 void SetColTextColor int col COLORREF color ; 设置列文本颜色 void SetItemTextColor int col int row COLORREF color ; void SetRowHeigt int nHeight ; 设置行高 void SetHeaderFontHW int nHeight int nWith ; 设置表头字体大小 void SetHeaderTextColor COLORREF color ; COLORREF m color; BOOL SetTextColor COLORREF cr ; void SetFontHW int nHeight int nWith ; 设置字体的高和宽 void EraseItemColor int col int row ; stColor FindItemColor2 int col int row COLORREF &color ; void EraseAllColor ;">可修改颜色的一个CListCtrlCl类 部分函数如下所示 public: 行高 int m nRowHeight; int InsertColumn int nCol LPCTSTR lpszColumnHeading int nFormat LVCFMT LEFT int nWidth 1 int nSubItem 1 ; public: Gradient 渐变系数 立体背景用 不用渐变设为0 [更多]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心若冰清自然开心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值