如何让listctrl控件中每一列显示不同颜色

 我来答
百度网友10a24bf
2018-01-24 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:95%
帮助的人:3192万
展开全部
下面这段代码是我写的一个例子,也是从CListCtrl从继承来的
bool CBaseTabCtrl::InitList()
{
//初始化列表框页
CRect rect_nlist;
this->GetClientRect(&rect_nlist);
rect_nlist.top+=100;
// m_list=new CListCtrl;
m_list->Create(WS_CHILD|LVS_REPORT|WS_BORDER|LVS_SINGLESEL,rect_nlist,this,ID_TABLIST);
this->m_list->ModifyStyle(LVS_EDITLABELS, 0L); //禁止标题编辑
m_list->ModifyStyle(0L, LVS_REPORT); //设为Report类型
地瓜说机
2018-01-24 · TA获得超过2.9万个赞
知道大有可为答主
回答量:2.3万
采纳率:91%
帮助的人:1.2亿
展开全部
给你一个封装类CReportCtrl,因为这里没有办法上传附件,所以只有直接粘贴了。如果你需要Demo代码,可以发邮件给我,我发给你:pigppy@163.com。
下面是头文件:
///////////////////////////////////////////////////////////////////////////////
// ReportCtrl.h
//
// CReportCtrl, a CListCtrl derived class that is specialized on "Report View"
// style.
//
// Features:
//
// 1, Item sorting by clicking on column header.
// 2, Sub-item text edit.
// 3, Item repositioning.
// 4, Customizing checkbox styles, including "single" and "disabled".
// 5, Sending a message to parent window when user clicks on a checkbox.
// 6, Convenient item insertion, deletion, moving, and sub-item text changing.
// 7, Sub-item images and color
// 8, And much more...
//
// This code may be used in compiled form in any way you desire. This file may be
// redistributed unmodified by any means PROVIDING it is not sold for profit without
// the authors written consent, and providing that this notice and the authors name
// is included. If the source code in this file is used in any commercial application
// then acknowledgement must be made to the author of this file .
//
// This file is provided "as is" with no expressed or implied warranty.
//
// Written by Bin Liu (abinn32@yahoo.com)
//
// History
//
// Nov. 26, 2003 - Initial release.
// Dec. 03, 2003 - Fixed a bug in "EndEdit" where item text were not preperly committed.
// Completed the implementation of the "Sort-Separator" feature.
// Jan. 01, 2004 - Fixed a bug in "SetItemData".
// - Added message "WM_EDIT_COMMITTED" which is sent to the parent window
// when an item text editing is committed.
// - Fixed a bug in "SetItemText"(double type).
// - Fixed a bug where item sorting does not work properly when there
// are multiple CReportCtrl objects on same window.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef __REPORTCTRL_H__
#define __REPORTCTRL_H__

// Sent to parent window when user clicked on the checkbox of an item:
// wParam: The item index in the list ctrl
// lParam: The mouse event type(WM_LBUTTONDOWN, WM_RBUTTONDOWN, etc) which generated this event.
// Note: This message is not sent when the checkbox states were altered programmatically
// by calling "SetItem", it is only sent when the user "physically" clicked the
// checkbox using mouse or joystick etc.
#define WM_ON_CHKBOX (WM_APP + 10000)

// Sent to parent window when a column of items were sorted
// wParam: The column index
// lParam: The sort method, either 0(descending) or 1(ascending)
#define WM_ITEM_SORTED (WM_APP + 10001)

// Sent to parent window when an item text editing was committed
// wParam: The item index
// lParam: The column index
#define WM_EDIT_COMMITTED (WM_APP + 10002)
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
就烦条0o
2018-01-24 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46499
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
下面是头文件:
///////////////////////////////////////////////////////////////////////////////
// ReportCtrl.h
//
// CReportCtrl, a CListCtrl derived class that is specialized on "Report View"
// style.
//
// Features:
//
// 1, Item sorting by clicking on column header.
// 2, Sub-item text edit.
// 3, Item repositioning.
// 4, Customizing checkbox styles, including "single" and "disabled".
// 5, Sending a message to parent window when user clicks on a checkbox.
// 6, Convenient item insertion, deletion, moving, and sub-item text changing.
// 7, Sub-item images and color
// 8, And much more...
//
// This code may be used in compiled form in any way you desire. This file may be
// redistributed unmodified by any means PROVIDING it is not sold for profit without
// the authors written consent, and providing that this notice and the authors name
// is included. If the source code in this file is used in any commercial application
// then acknowledgement must be made to the author of this file .
//
// This file is provided "as is" with no expressed or implied warranty.
//
// Written by Bin Liu (abinn32@yahoo.com)
//
// History
//
// Nov. 26, 2003 - Initial release.
// Dec. 03, 2003 - Fixed a bug in "EndEdit" where item text were not preperly committed.
// Completed the implementation of the "Sort-Separator" feature.
// Jan. 01, 2004 - Fixed a bug in "SetItemData".
// - Added message "WM_EDIT_COMMITTED" which is sent to the parent window
// when an item text editing is committed.
// - Fixed a bug in "SetItemText"(double type).
// - Fixed a bug where item sorting does not work properly when there
// are multiple CReportCtrl objects on same window.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef __REPORTCTRL_H__
#define __REPORTCTRL_H__

// Sent to parent window when user clicked on the checkbox of an item:
// wParam: The item index in the list ctrl
// lParam: The mouse event type(WM_LBUTTONDOWN, WM_RBUTTONDOWN, etc) which generated this event.
// Note: This message is not sent when the checkbox states were altered programmatically
// by calling "SetItem", it is only sent when the user "physically" clicked the
// checkbox using mouse or joystick etc.
#define WM_ON_CHKBOX (WM_APP + 10000)

// Sent to parent window when a column of items were sorted
// wParam: The column index
// lParam: The sort method, either 0(descending) or 1(ascending)
#define WM_ITEM_SORTED (WM_APP + 10001)

// Sent to parent window when an item text editing was committed
// wParam: The item index
// lParam: The column index
#define WM_EDIT_COMMITTED (WM_APP + 10002)

// Checkbox styles.
#define RC_CHKBOX_NONE 0 // No checkbox displayed
#define RC_CHKBOX_NORMAL 1 // Normal, multiple check allowed
#define RC_CHKBOX_SINGLE 2 // Single check only
#define RC_CHKBOX_DISABLED 3 // Disabled, cannot be checked/unchecked by user input,
// but can be by your code.

// Item state flags for selection, deletion, etc.
// Multiple flags can be combined together using the bit-or operator.
// Note: If RC_ITEM_ALL is set, all other flags are ignored
#define RC_ITEM_NONE 0x0000 // Void, indicates invalid items only
#define RC_ITEM_ALL 0x0001 // All items regardless of states
#define RC_ITEM_SELECTED 0x0002 // Selected items
#define RC_ITEM_UNSELECTED 0x0004 // Unselected items
#define RC_ITEM_CHECKED 0x0008 // Checked items
#define RC_ITEM_UNCHECKED 0x0010 // Unchecked items
#define RC_ITEM_FOCUSED 0x0020 // Focused item
#define RC_ITEM_UNFOCUSED 0x0040 // Unfocused items

// Item inverting types
#define RC_INVERT_SELECTION 0 // Invert item selection
#define RC_INVERT_CHECKMARK 1 // Invert item check mark

// Removes any custom color from item text and item backgroun
#define COLOR_INVALID 0xffffffff

//////////////////////////////////////////////////////////////////////////
// The CReportCtrl Class Definition
//////////////////////////////////////////////////////////////////////////

class CReportCtrl : public CListCtrl
{
public:

//////////////////////////////////////////////////////////////////////
// Constructor & Destructor
//////////////////////////////////////////////////////////////////////
CReportCtrl();
virtual ~CReportCtrl();

//////////////////////////////////////////////////////////////////////
// Run-time Creation
//////////////////////////////////////////////////////////////////////
virtual BOOL Create(CWnd* pParentWnd, UINT nID, LPCRECT lpRect = NULL, DWORD dwStyle = WS_BORDER | WS_TABSTOP);

///////////////////////////////////////////////////////////////////////
// Column Header attributes
///////////////////////////////////////////////////////////////////////

BOOL SetColumnHeader(const CString& strHeadings); // Set columns and their formats.
int GetColumnCount() const; // Get the column count.
BOOL DeleteAllColumns();
CString GetHeaderText(int nColumn) const;
BOOL SetHeaderText(int nColumn, LPCTSTR lpText);
BOOL HasColumnHeader() const; // FALSE if the list control has LVS_NOCOLUMNHEADER flag
const CHeaderCtrl* GetHeaderCtrl() const;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式