随笔 - 67  文章 - 171  trackbacks - 0
<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(10)

随笔分类

随笔档案

连接资料

最新随笔

搜索

  •  

最新随笔

最新评论

void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);

LVITEM lvi = {0};
lvi.mask = LVIF_STATE;//|LVIF_IMAGE;
lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED ;
lvi.iItem = lpDIS->itemID;
BOOL bGet = GetItem(&lvi);

BOOL bHighlight =((lvi.state & LVIS_DROPHILITED)||((lvi.state & LVIS_SELECTED) &&
((GetFocus() == this)|| (GetStyle() & LVS_SHOWSELALWAYS))));

// 画文本背景
CRect rcBack = lpDIS->rcItem;
pDC->SetBkMode(TRANSPARENT);
if( bHighlight )
{
pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));

pDC->FillRect(rcBack, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
}
else
{
if (lpDIS->itemID%2 ==0)
{
pDC->SetTextColor(0x0C0F80);
pDC->FillRect(rcBack, &CBrush(0xEEF1E3));
}
else
{
pDC->SetTextColor(RGB(0,128,255));
pDC->FillRect(rcBack, &CBrush(0xE3e3e3));
}
}

//设置字体颜色
CString str;

//得到焦点大小
CRect rcFocus = lpDIS->rcItem;
rcFocus.DeflateRect(1,1,1,1);

if (lpDIS->itemAction & ODA_DRAWENTIRE)
{
//写文本
CString szText;
for (int i = 0; i < /*GetColumns()*/10; i++)
{ //循环得到文本
CRect rcItem;
if ( !GetSubItemRect(lpDIS->itemID, i, LVIR_LABEL, rcItem ))
continue;
szText = GetItemText( lpDIS->itemID, i );

rcItem.left += 5; rcItem.right -= 1;
pDC->DrawText(szText/*szText*/, lstrlen(szText), &rcItem, DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE);
}
}

}

posted on 2008-02-03 13:00 cpsprogramer 阅读(4224) 评论(0)  编辑 收藏 引用 所属分类: VC++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理