自绘CListCtrl类 奇偶行颜色设置
来源:互联网 发布:阿里云数据库使用教程 编辑:程序博客网 时间:2024/06/05 20:30
//自绘CListCtrl类,重载虚函数DrawItemvoid CNewListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct){ // TODO: Add your code to draw the specified item ASSERT(lpDrawItemStruct->CtlType == ODT_LISTVIEW); CDC dc; dc.Attach(lpDrawItemStruct->hDC); ASSERT(NULL != dc.GetSafeHdc()); // Save these value to restore them when done drawing. COLORREF crOldTextColor = dc.GetTextColor(); COLORREF crOldBkColor = dc.GetBkColor(); // If this item is selected, set the background color // and the text color to appropriate values. Also, erase // rect by filling it with the background color. if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT)); } else { if(lpDrawItemStruct->itemID%2) dc.FillSolidRect(&lpDrawItemStruct->rcItem, RGB(128,128,128)); else dc.FillSolidRect(&lpDrawItemStruct->rcItem, RGB(255,128,255)); } // If this item has the focus, draw a red frame around the // item's rect. if ((lpDrawItemStruct->itemAction | ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS)) { CBrush br(RGB(0, 0, 128)); dc.FrameRect(&lpDrawItemStruct->rcItem, &br); } // Draw the text. CString strText(_T("")); CRect rcItem; for(int i=0; i<GetHeaderCtrl()->GetItemCount(); i++) { strText = GetItemText(lpDrawItemStruct->itemID, i); GetSubItemRect(lpDrawItemStruct->itemID, i, LVIR_LABEL, rcItem); rcItem.left += 5; dc.DrawText( strText, strText.GetLength(), &rcItem, DT_LEFT|DT_SINGLELINE|DT_VCENTER); } // Reset the background color and the text color back to their // original values. dc.SetTextColor(crOldTextColor); dc.SetBkColor(crOldBkColor); dc.Detach();}// 调用CNewListCtrl m_list; // 类的成员变量 #define IDC_LIST 0x1101 m_list.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL|WS_HSCROLL|LVS_OWNERDRAWFIXED, CRect(0, 0, 280, 280), this, IDC_LIST); m_list.ModifyStyle(0, LVS_REPORT|LVS_SINGLESEL); m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); m_list.InsertColumn(0, _T("AAA"), LVCFMT_LEFT, 100); m_list.InsertColumn(1, _T("BBB"), LVCFMT_LEFT, 100); CString strText(_T("")); for(int i=0; i<20; i++) { m_list.InsertItem(i, _T("")); strText.Format(_T("%d - Hello, World!"), i+1); m_list.SetItemText(i, 0, strText); strText.Format(_T("%d - ABCDEFG"), i+1); m_list.SetItemText(i, 1, strText); }
效果如图:
本文转自:http://blog.csdn.net/VisualEleven/article/details/5948057
- 自绘CListCtrl类 奇偶行颜色设置
- 自绘CListCtrl 间隔行颜色变换
- clistCtrl 自绘 设置行高 行宽
- clistCtrl 自绘 设置行高 行宽
- 自绘CListCtrl类
- 自绘CListCtrl类
- 自绘CListCtrl类
- 设置 Excel 奇偶行背景颜色
- 设置 Excel 奇偶行背景颜色
- Birt 报表奇偶行颜色不同设置
- Gridview中奇偶数行颜色设置
- 设置某一行背景颜色的CListCtrl
- 设置某一行背景颜色的CListCtrl
- 设置某一行背景颜色的CListCtrl
- 设置CListCtrl某一行背景颜色
- 设置CListCtrl单元格的颜色
- MFC list control 奇偶行颜色不同设置
- mfc 设置、清除列表框(CListctrl)行颜色
- MediaInfo使用简介(新版本支持HEVC)
- 某度面试题
- git学习二
- 一个网络资深者发起的思考
- C++经典开源库
- 自绘CListCtrl类 奇偶行颜色设置
- 导出xml格式的文件
- Hadoop源码解析之: HBase Security
- 外层div宽度固定,而内层div宽度有变化,css怎样使一个使内层div水平居中,css实现分页效果及分页居中问题解决
- Android TabHost +Fragment 实现底部菜单栏 .
- mysql创建存储过程
- MFC ListCtrl使用指南
- 关于Sencha Touch2中Cmd的用法
- Action bar实现