15,979
社区成员
发帖
与我相关
我的任务
分享
m_pListCtrl = new CListCtrl;
m_pListCtrl->Create(WS_CHILD | LVS_SINGLESEL | LVS_REPORT | \
LVS_SORTASCENDING , m_rectListTestItem, (CWnd*)&m_tabStation, ID_STATION_ITEM_LIST_MIN);
m_pListCtrl->SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); //enable full row select property
void CxxView::OnNMCustomdrawList(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT;
//
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if(CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) //此条件一直成立,为什么? {
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if(CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage)
{
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage)
{
COLORREF clrNewBkColor;
int nItem = static_cast<int>(pLVCD->nmcd.dwItemSpec);
//Do something to change Item color...
}
//*pResult = 0;
}
void CxxListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
int iRow = 0;
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_DODEFAULT;
iRow = lplvcd->nmcd.dwItemSpec;
if (this->GetItemText(iRow, ITEM_STATUS) == _T("PASS")) //对Item进行条件筛选
{
lplvcd->clrTextBk = RGB(0, 255, 0);
}
else if (this->GetItemText(iRow, ITEM_STATUS) == _T("FAIL"))
{
lplvcd->clrTextBk = RGB(255, 0, 0);
}
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
default:
*pResult = CDRF_DODEFAULT;
}
}