So easy! (但是我不会)在ListCtrl中怎样给指定行设置不同颜色?? 实在没多少分了,先给10分吧,高手救命呀! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.vckbase.com/document/viewdoc/?id=891 m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP); m_ListCtrl.SetBkColor(RGB(177,151,240)); m_ListCtrl.SetTextColor(RGB(0,0,0)); m_ListCtrl.SetTextBkColor(RGB(177,151,240)); 这个功能比较困难因为好像是List的一个缺陷 void CRecordList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your message handler code here and/or call default CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rcItem(lpDrawItemStruct->rcItem); int nItem = lpDrawItemStruct->itemID; BOOL bFocus = (GetFocus() == this); COLORREF clrTextSave, clrBkSave; static _TCHAR szBuff[MAX_PATH]; LPCTSTR pszText;// get item data LV_ITEM lvi; lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvi.iItem = nItem; lvi.iSubItem = 0; lvi.pszText = szBuff; lvi.cchTextMax = sizeof(szBuff); lvi.stateMask = 0xFFFF; // get all state flags GetItem(&lvi); BOOL bSelected = (bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED; bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);// set colors if item is selected CRect rcAllLabels; GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS); rcAllLabels.left = 0; if (rcAllLabels.right<m_cxClient) rcAllLabels.right = m_cxClient; if (bSelected) { clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); pDC->FillRect(rcAllLabels, &CBrush(::GetSysColor(COLOR_HIGHLIGHT))); } else { pDC->FillRect(rcAllLabels, &CBrush(GetItemData(nItem))); } pszText=szBuff; GetItemRect(nItem, rcItem, LVIR_LABEL); pszText = MakeShortString(pDC, szBuff, rcItem.right-rcItem.left, 0); pDC->DrawText(pszText,-1,rcItem,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER); LV_COLUMN lvc; lvc.mask = LVCF_FMT | LVCF_WIDTH; for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++) { rcItem.left = rcItem.right; rcItem.right += lvc.cx; int nRetLen = GetItemText(nItem, nColumn,szBuff, sizeof(szBuff)); if (nRetLen == 0) continue; pszText = MakeShortString(pDC, szBuff, rcItem.right - rcItem.left, 0); UINT nJustify = DT_LEFT; if(pszText == szBuff) { switch(lvc.fmt & LVCFMT_JUSTIFYMASK) { case LVCFMT_RIGHT: nJustify = DT_RIGHT; break; case LVCFMT_CENTER: nJustify = DT_CENTER; break; default: break; } } pDC->DrawText(pszText, -1, rcItem, nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER); }// draw focus rectangle if item has focus if (lvi.state & LVIS_FOCUSED && bFocus) pDC->DrawFocusRect(rcAllLabels); // set original colors if item was selected if (bSelected) { pDC->SetTextColor(clrTextSave); pDC->SetBkColor(clrBkSave); }// AfxMessageBox("draw item");}m_MyList.SetItemData(i,(DWORD)RGB(255,0,0)); 使用XListCtrl类,在vckbase上可以找到。 MFC ActiveX调用带MFC对话框的DLL产生的问题 如何确定一个用户 如何修改文件描述 请教有关互斥量和非模式对话框唯一的问题 求教,CString类中的left,right,mid函数 ole db 问题!为什么有日期时间字段的记录,当日期为空时,记录就不能修改? dwRemoteProcess == (DWORD)-1中DWORD不就是个类型吗,在这里是什么意思啊 编写一个基本的COM,共有几个文件?他们分别是哪些?各有什么作用? 各位,北京哪个培训班VC讲的好?偶需要培训,谢谢大家了 有关动态创建菜单的问题 请教龚建伟老师的串口调试助手的问题 为什么线程数不同?
m_ListCtrl.SetBkColor(RGB(177,151,240));
m_ListCtrl.SetTextColor(RGB(0,0,0));
m_ListCtrl.SetTextBkColor(RGB(177,151,240));
因为好像是List的一个缺陷
{
// TODO: Add your message handler code here and/or call default
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rcItem(lpDrawItemStruct->rcItem);
int nItem = lpDrawItemStruct->itemID;
BOOL bFocus = (GetFocus() == this);
COLORREF clrTextSave, clrBkSave; static _TCHAR szBuff[MAX_PATH];
LPCTSTR pszText;// get item data LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
lvi.iItem = nItem;
lvi.iSubItem = 0;
lvi.pszText = szBuff;
lvi.cchTextMax = sizeof(szBuff);
lvi.stateMask = 0xFFFF; // get all state flags
GetItem(&lvi); BOOL bSelected = (bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED;
bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);// set colors if item is selected
CRect rcAllLabels;
GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
rcAllLabels.left = 0;
if (rcAllLabels.right<m_cxClient)
rcAllLabels.right = m_cxClient; if (bSelected)
{
clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
pDC->FillRect(rcAllLabels, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
}
else
{
pDC->FillRect(rcAllLabels, &CBrush(GetItemData(nItem)));
} pszText=szBuff; GetItemRect(nItem, rcItem, LVIR_LABEL);
pszText = MakeShortString(pDC, szBuff,
rcItem.right-rcItem.left, 0); pDC->DrawText(pszText,-1,rcItem,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER); LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH; for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++)
{
rcItem.left = rcItem.right;
rcItem.right += lvc.cx; int nRetLen = GetItemText(nItem, nColumn,szBuff, sizeof(szBuff));
if (nRetLen == 0)
continue; pszText = MakeShortString(pDC, szBuff,
rcItem.right - rcItem.left, 0); UINT nJustify = DT_LEFT; if(pszText == szBuff)
{
switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
{
case LVCFMT_RIGHT:
nJustify = DT_RIGHT;
break;
case LVCFMT_CENTER:
nJustify = DT_CENTER;
break;
default:
break;
}
}
pDC->DrawText(pszText, -1, rcItem,
nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
}// draw focus rectangle if item has focus if (lvi.state & LVIS_FOCUSED && bFocus)
pDC->DrawFocusRect(rcAllLabels); // set original colors if item was selected if (bSelected)
{
pDC->SetTextColor(clrTextSave);
pDC->SetBkColor(clrBkSave);
}
// AfxMessageBox("draw item");
}m_MyList.SetItemData(i,(DWORD)RGB(255,0,0));