首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

设立ListCtrl列表控件其中某一行的字体和背景颜色

2013-10-12 
设置ListCtrl列表控件其中某一行的字体和背景颜色设置ListCtrl列表控件其中某一行的字体和背景颜色,可以最

设置ListCtrl列表控件其中某一行的字体和背景颜色

设置ListCtrl列表控件其中某一行的字体和背景颜色,可以最终达到如下效果:

设立ListCtrl列表控件其中某一行的字体和背景颜色

操作步骤如下所示:

1.先添加一个自定义消息

//ListCtrl加颜色void CSpecialVH264Dlg::OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult ){//This code based on Michael Dunn's excellent article on//list control custom draw at http://www.codeproject.com/listctrl/lvcustomdraw.aspNMLVCUSTOMDRAW* 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 clrNewTextColor, clrNewBkColor;int    nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );CString strTemp = m_vh264nallist.GetItemText(nItem,2);if(strcmp(strTemp,"SLICE")==0){clrNewTextColor = RGB(0,0,0);//Set the text clrNewBkColor = RGB(0,255,255);//青色}else if(strcmp(strTemp,"SPS")==0){clrNewTextColor = RGB(0,0,0);//text clrNewBkColor = RGB(255,255,0);//黄色}else if(strcmp(strTemp,"PPS")==0){clrNewTextColor = RGB(0,0,0);//textclrNewBkColor = RGB(255,153,0);//咖啡色}else if(strcmp(strTemp,"SEI")==0){clrNewTextColor = RGB(0,0,0);//textclrNewBkColor = RGB(255,66,255);//粉红色}else if(strcmp(strTemp,"IDR_SLICE")==0){clrNewTextColor = RGB(0,0,0);//textclrNewBkColor = RGB(255,0,0);//红色}else{clrNewTextColor = RGB(0,0,0);//textclrNewBkColor = RGB(255,255,255);//白色}pLVCD->clrText = clrNewTextColor;pLVCD->clrTextBk = clrNewBkColor;// Tell Windows to paint the control itself.*pResult = CDRF_DODEFAULT;}}


热点排行