分享

自绘列表头

 3D建模仿真 2014-09-10
1、响应ON_WM_PAINT()设置表头的字体以及颜色
CPaintDC dc(this); // device context for painting
 CRect rect;
 GetClientRect(rect);
 dc.FillSolidRect(rect,m_clrHead/*RGB(147,212,255)*/);   //重绘标题栏颜色
 int nItems = GetItemCount();
 CRect rectItem;
 CPen m_pen(PS_SOLID,1,m_clrHeadItem/*RGB(211,211,211)*/);      //分隔线颜色
 CPen * pOldPen=dc.SelectObject(&m_pen);
 CFont m_font;
 //m_font.Attach(m_fontHead);
 m_font.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_T("微软雅黑"));//创建字体
 //m_font.CreatePointFont(200,"宋体");        //字体
 CFont * pOldFont=dc.SelectObject(&m_font);
 dc.SetTextColor(m_clrHeadText/*RGB(13,141,237)*/);     //字体颜色
 for(int i = 0; i <nItems; i++)                    //对标题的每个列进行重绘
 { 
  GetItemRect(i, &rectItem);
  rectItem.top+=2;
  rectItem.bottom+=2;
  dc.MoveTo(rectItem.right,rect.top);                //重绘分隔栏
  dc.LineTo(rectItem.right,rectItem.bottom);
  TCHAR buf[256];
  HD_ITEM hditem;
  hditem.mask = HDI_TEXT | HDI_FORMAT | HDI_ORDER;
  hditem.pszText = buf;
  hditem.cchTextMax = 255;
  GetItem( i, &hditem );                                       //获取当然列的文字
  UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_TOP |DT_CENTER | DT_END_ELLIPSIS ;
  dc.DrawText(buf, &rectItem, uFormat);           //重绘标题栏的文字
 }
 dc.SelectObject(pOldPen);
 dc.SelectObject(pOldFont);

 2、ON_MESSAGE(HDM_LAYOUT, OnLayout)设置表头高度
LRESULT CHeaderCtrlEX::OnLayout( WPARAM wParam, LPARAM lParam )
{
 LRESULT lResult = CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam);
 HD_LAYOUT &hdl = *( HD_LAYOUT * ) lParam;
 RECT *prc = hdl.prc;
 WINDOWPOS *pwpos = hdl.pwpos;
 //表头高度为原来1.5倍,如果要动态修改表头高度的话,将1.5设成一个全局变量
 int nHeight = (int)(pwpos->cy * m_Height);
 pwpos->cy = nHeight;
 prc->top = nHeight;
 return lResult;
}
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多