自己的OnCustomdraw

void CDSelect::OnNMCustomdrawLcselect(NMHDR *pNMHDR, LRESULT *pResult)
{
 LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
 // TODO: 在此添加控件通知处理程序代码

 *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.

 LPNMLVCUSTOMDRAW  pLVCD = (LPNMLVCUSTOMDRAW)pNMHDR;

 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
 {
  *pResult = CDRF_NOTIFYITEMDRAW;
 }
 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
 {
  // This is the prepaint stage for an item. Here's where we set the
  // item's text color. Our return value will tell Windows to draw the
  // item itself, but it will use the new color we set here.
  // We'll cycle the colors through red, green, and light blue.

  int nItem   =   static_cast<int>(   pLVCD->nmcd.dwItemSpec   );
  //字体颜色
  COLORREF crText = RGB(0,100,240);
     if (_T("0") == m_LCselect.GetItemText(nItem,6))
     {
   crText = RGB(200,200,200);
     }
       pLVCD->clrText = crText;

    //高亮颜色

/*
    if( m_LCselect.GetItemState(nItem, CDIS_SELECTED) )
    { // 预留BUG,看有多少人是摘自这里, CDIS_SELECTED前少取反号,且把异或为与
     pLVCD->nmcd.uItemState ^= CDIS_SELECTED;// 预留BUG
                 //pLVCD->nmcd.uItemState = CDIS_SELECTED;
     pLVCD->clrTextBk =RGB(0, 0, 120);
     //pLVCD->clrText   = RGB(0, 0, 255);   
     *pResult = CDRF_NEWFONT;
     //return;
    }
*/
    /*

    if( m_LCselect.GetItemState(nItem, LVIS_SELECTED) == LVIS_SELECTED )
    {
    pLVCD->clrTextBk =RGB(255, 0, 0);
    *pResult = CDRF_NEWFONT;
    return;
    }
    */


/*
  POSITION pos = m_LCselect.GetFirstSelectedItemPosition();
  int ntpItem = 0;
  if (pos == NULL)
   return;
  else
  {
   while (pos)
   {
    int ntpItem = m_LCselect.GetNextSelectedItem(pos);
    //TRACE1("Item %d was selected!/n", nItem);
    // you could do your own processing on nItem here
   }
  }

*/
  /*
       if (pLVCD->nmcd.uItemState == CDIS_FOCUS)
       {
    // pLVCD->clrText = RGB(255,0,0);
     pLVCD->clrTextBk = RGB(255,0,0);
     *pResult = CDRF_NEWFONT;
     return;

       }
    */
/*

  if ( (pLVCD->nmcd.dwItemSpec % 3) == 0 )
   
  else if ( (pLVCD->nmcd.dwItemSpec % 3) == 1 )
   crText = RGB(0,255,0);
  else
   crText = RGB(128,128,255);

  // Store the color back in the NMLVCUSTOMDRAW struct.
  

  // Tell Windows to paint the control itself.
   */
  *pResult = CDRF_DODEFAULT;
  //return;
 }
  if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
 {
  // 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.
  // The text color will cycle through red, green, and light blue.
  // The background color will be light blue for column 0, red for
  // column 1, and black for column 2.

  COLORREF crText;
        int nItem   =   static_cast<int>(   pLVCD->nmcd.dwItemSpec   );
  if ( m_LCselect.GetItemText (nItem,6) == _T("0"))
  {
   crText = RGB(255,0,0);
  }
  // Store the colors back in the NMLVCUSTOMDRAW struct.
  pLVCD->clrText = crText;
  //pLVCD->clrTextBk = crBkgnd;

  // Tell Windows to paint the control itself.
  *pResult = CDRF_DODEFAULT;
 }

 

 //高亮颜色设置
 /*
 else   if   (   (CDDS_ITEMPREPAINT   |   CDDS_SUBITEM)   ==   pLVCD->nmcd.dwDrawStage   )  
 {  
  //   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.  

  //   Store   the   colors   back   in   the   NMLVCUSTOMDRAW   struct.  
  int   nItem=(int)(pLVCD->nmcd.dwItemSpec);  
  if((m_LCselect.GetItemState(nItem,   LVIS_SELECTED)==LVIS_SELECTED)){  
   //pLVCD->clrText   =   RGB(255,155,255);  
   pLVCD->clrTextBk   =   RGB(10,80,10);  
  }  
  //   Tell   Windows   to   paint   the   control   itself.  
  *pResult   =   CDRF_DODEFAULT;  
 }  
*/


 //*pResult = 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值