CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

如何设置CListCtrl中任一行的背景颜色,

楼主flying720()2006-12-03 20:37:30 在 VC/MFC / 基础类 提问

困扰我很久的一个问题,总得不到预想的效果.  
  比如说设置CListCtrl中第一行的为蓝色,  
  第二行为红色,这样交替变色。  
   
  多谢高手指点一二,感激涕零 问题点数:20、回复次数:4Top

1 楼jinghao666666(努力工作!!!)回复于 2006-12-03 21:01:09 得分 0

查下msdn,或从网上下个别人写好的。Top

2 楼zhshgap(努力学习)回复于 2006-12-03 21:04:41 得分 0

这个只能自定义派生clistctrl类  
  网上应该有很多例子Top

3 楼erdgzw(编译通过那一刻感觉真好)回复于 2006-12-03 22:11:11 得分 0

你应该使用WindowsApi来创建List   Control,并启用拥有者自绘。Top

4 楼ljhjason(小鬼)回复于 2006-12-03 22:15:20 得分 0

我这个是改某列的字体,修改一下就可以改颜色.  
   
  void   CMyDlg::OnNMCustomdrawList1(NMHDR   *pNMHDR,   LRESULT   *pResult)  
  {  
  LPNMLVCUSTOMDRAW   pLVCD   =   reinterpret_cast<LPNMLVCUSTOMDRAW>(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   (pLVCD->nmcd.dwDrawStage   ==   CDDS_PREPAINT)  
  {  
  *pResult   =   CDRF_NOTIFYITEMDRAW;  
  }  
  else   if   (pLVCD->nmcd.dwDrawStage   ==   CDDS_ITEMPREPAINT)  
  {  
  //   This   is   the   notification   message   for   an   item.     We'll   request  
  //   notifications   before   each   subitem's   prepaint   stage.  
   
  *pResult   =   CDRF_NOTIFYSUBITEMDRAW;//CDRF_NOTIFYPOSTPAINT;  
  }  
  else   if   (pLVCD->nmcd.dwDrawStage   ==     (CDDS_ITEMPREPAINT   |   CDDS_SUBITEM))  
  {  
  //   This   is   the   prepaint   stage   for   a   subitem.   Here's   where   we   set   the  
  //   item's   text   and   background   colors.   Our   return   value   will   tell  
  //   Windows   to   draw   the   subitem   itself,   but   it   will   use   the   new   colors  
  //   we   set   here.  
   
  //int   nItem   =   static_cast<int>   (pLVCD->nmcd.dwItemSpec);  
  int   nSubItem   =   pLVCD->iSubItem;  
  CDC*   pDC   =   CDC::FromHandle(pLVCD->nmcd.hdc);  
  if(nSubItem==3)  
  {  
  pDC->SelectObject(&font);  
  }else  
  {  
  pDC->SelectObject(oldfont);  
  }  
  *pResult   =   CDRF_DODEFAULT;  
   
  }  
  }Top

相关问题

关键词

得分解答快速导航

  • 帖主:flying720

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo