mfc ListControl 重绘网格线

.h文件

 //网格线设置 [yal 2013.10.08]
 int        m_nGridStyle;      //风格 PS_DASH,PS_SOLID,。。。
 COLORREF   m_GridColor;       //颜色
 int        m_nGridWeigth;     //粗度1,2,...

 void  setGridStyle(int nStyle);
 void  setGridWeight(int nWeight);
 void  setGridColor(COLORREF cr);

.cpp文件

CListCtrlCl::CListCtrlCl()
:m_nGridStyle(PS_SOLID)
,m_nGridWeigth(1)
,m_GridColor(RGB(255,255,255))
{
}
void CListCtrlCl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{

 // TODO:  添加您的代码以绘制指定项

 // 重绘网格线 [7/12/2013 dell]
 const MSG *msg = GetCurrentMessage();
 DefWindowProc( msg->message, msg->wParam, msg->lParam );

 // Draw the lines only for LVS_REPORT mode
 if( (GetStyle() & LVS_TYPEMASK) == LVS_REPORT )
 {
  // Get the number of columns
  CClientDC dc(this );
  //yal 2013.10.08画有颜色的线
  CPen pen(m_nGridStyle,m_nGridWeigth,m_GridColor);
  CPen* oldpen=dc.SelectObject(&pen);

  CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
  int nColumnCount = pHeader->GetItemCount();

  // The bottom of the header corresponds to the top of the line
  RECT rect, rectCol;
  pHeader->GetClientRect( &rect );
  int top = rect.bottom;

  // Now get the client rect so we know the line length and
  // when to stop
  GetClientRect( &rect );

  if( !GetItemRect( 1, &rectCol, LVIR_BOUNDS ))
   return;

  int height1 = rectCol.bottom - rectCol.top;

  // The border of the column is offset by the horz scroll
  int borderx = 0 - GetScrollPos( SB_HORZ );
  for( int i = 0; i < nColumnCount; i++ )
  {
   // Get the next border
   borderx += GetColumnWidth( i );

   // if next border is outside client area, break out
   if( borderx >= rect.right ) break;

   // Draw the line.
   dc.MoveTo( borderx-1, top/*top*/);
   dc.LineTo( borderx-1, height1+top+lpDrawItemStruct->itemID*height1/*nColumnCount*height1 + top*/);
  }

  // Draw the horizontal grid lines

  // First get the height
  if( !GetItemRect( 0, &rect, LVIR_BOUNDS ))
   return;

  int height = rect.bottom - rect.top;

  GetClientRect( &rect );
  int width = rect.right;

  for(unsigned int i = 1; i <= lpDrawItemStruct->itemID+1; i++ )
  {
   dc.MoveTo( 0, top + height*i);
   dc.LineTo( width, top + height*i );
  }

   dc.SelectObject(oldpen);
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值