-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColoredListCtrl.cpp
More file actions
176 lines (143 loc) · 3.45 KB
/
Copy pathColoredListCtrl.cpp
File metadata and controls
176 lines (143 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// ColoredListCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "ColoredListCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColoredListCtrl
CColoredListCtrl::CColoredListCtrl()
{
//m_colRow1 = RGB(220,220,220);
//m_colRow2 = RGB(247,247,247);
m_colRow1 = RGB(240,247,249);
m_colRow2 = RGB(229,232,239);
m_colSelected = RGB(128,0,128);
m_nSelectedRow = -1;
m_nSelectedColumn = -1;
m_nSubSelectedColumn = -1;
m_nSubSubSelectedColumn = -1;
m_nRowStateColumn = -1;
m_RowState.clear();
}
CColoredListCtrl::~CColoredListCtrl()
{
}
BEGIN_MESSAGE_MAP(CColoredListCtrl, CListCtrl)
//{{AFX_MSG_MAP(CColoredListCtrl)
ON_WM_ERASEBKGND()
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColoredListCtrl message handlers
void CColoredListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
int iRow = lplvcd->nmcd.dwItemSpec;
int iCol = lplvcd->iSubItem;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT :
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
}
// Modify item text and or background
case CDDS_ITEMPREPAINT:
{
lplvcd->clrText = RGB(0,0,0);
// If you want the sub items the same as the item,
// set *pResult to CDRF_NEWFONT
*pResult = CDRF_NOTIFYSUBITEMDRAW;
return;
}
// Modify sub item text and/or background
case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM:
{
if(iRow == m_nSelectedRow)
{
lplvcd->clrTextBk = m_colSelected;
if(iCol == m_nSelectedColumn)
{
lplvcd->clrTextBk = RGB(255,0,0);
}
else if(iCol == m_nSubSelectedColumn)
{
lplvcd->clrTextBk = RGB(0,0,255);
}
else if(iCol == m_nSubSubSelectedColumn)
{
lplvcd->clrTextBk = RGB(0,0,255);
}
else
{
lplvcd->clrText = RGB(0,0,0);
}
lplvcd->clrText = RGB(255,255,255);
if (iCol == m_nRowStateColumn)
{
switch (m_RowState[iRow])
{
case 0: lplvcd->clrText = RGB(255, 255, 255); break;
case 1: lplvcd->clrText = RGB(0, 255, 0); break;
case 2: lplvcd->clrText = RGB(255, 255, 0); break;
case 3: lplvcd->clrText = RGB(255, 0, 0); break;
}
}
}
else
{
if(iRow %2)
{
lplvcd->clrTextBk = m_colRow2;
}
else
{
lplvcd->clrTextBk = m_colRow1;
}
if (iCol == m_nRowStateColumn)
{
switch (m_RowState[iRow])
{
case 0: lplvcd->clrText = RGB(0, 0, 0); break;
case 1: lplvcd->clrText = RGB(0, 128, 0); break;
case 2: lplvcd->clrText = RGB(128, 128, 0); break;
case 3: lplvcd->clrText = RGB(200, 0, 0); break;
}
}
else
{
lplvcd->clrText = RGB(0, 0, 0);
}
}
*pResult = CDRF_DODEFAULT;
return;
}
}
}
BOOL CColoredListCtrl::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
CColoredListCtrl::GetClientRect(rect);
POINT mypoint;
CBrush brush0(m_colRow1);
CBrush brush1(m_colRow2);
int chunk_height=GetCountPerPage();
pDC->FillRect(&rect,&brush1);
for (int i=0;i<=chunk_height;i++)
{
GetItemPosition(i,&mypoint);
rect.top=mypoint.y ;
GetItemPosition(i+1,&mypoint);
rect.bottom =mypoint.y;
pDC->FillRect(&rect,i %2 ? &brush1 : &brush0);
}
brush0.DeleteObject();
brush1.DeleteObject();
return FALSE;
}