-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExtProgressCtrl.cpp
198 lines (129 loc) · 4.58 KB
/
ExtProgressCtrl.cpp
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// ExtProgress.cpp : implementation file
//
#include "stdafx.h"
#include "cpubench2004.h"
#include "ExtProgressCtrl.h"
#include "gradient.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExtProgress
CExtProgressCtrl::CExtProgressCtrl()
{
m_alertPos=0;
m_bLessThan=TRUE;
}
CExtProgressCtrl::~CExtProgressCtrl()
{
}
BEGIN_MESSAGE_MAP(CExtProgressCtrl, CProgressCtrl)
//{{AFX_MSG_MAP(CExtProgressCtrl)
ON_WM_ERASEBKGND()
ON_WM_DRAWITEM()
ON_WM_NCPAINT()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExtProgress message handlers
BOOL CExtProgressCtrl::OnEraseBkgnd(CDC* pDC)
{
CRect r;
GetClientRect(&r);
CGradient g;
g.SetGradientColors(RGB(255,255,255),RGB(255,255,255));
g.SetDirection(CGradient::TTB);
g.DrawLinearGradient(pDC,CRect(r.left+1,r.top+3,r.right-2,r.bottom-4));
g.SetGradientColors(RGB(255,255,255),RGB(230,230,224));
g.SetDirection(CGradient::TTB);
g.DrawLinearGradient(pDC,CRect(r.left+1,r.bottom-4,r.right-2,r.bottom-2));
g.SetGradientColors(RGB(200,200,194),RGB(255,255,255));
g.SetDirection(CGradient::TTB);
g.DrawLinearGradient(pDC,CRect(r.left+1,r.top,r.right-2,r.top+3));
CPen p1(PS_SOLID,1,RGB(0,60,116));
CPen p2(PS_SOLID,1,RGB(104,136,160));
CPen p3(PS_SOLID,1,RGB(191,206,220));
pDC->SelectObject(&p1);
pDC->MoveTo(r.left+1,r.top);
pDC->LineTo(r.right-2,r.top);
pDC->SelectObject(&p2);
pDC->LineTo(r.right-2,r.top);
pDC->LineTo(r.right-2,r.top+1);
pDC->LineTo(r.right-1,r.top+1);
pDC->SelectObject(&p1);
pDC->LineTo(r.right-1,r.bottom-2);
pDC->SelectObject(&p2);
pDC->LineTo(r.right-1,r.bottom-2);
pDC->LineTo(r.right-2,r.bottom-2);
pDC->LineTo(r.right-2,r.bottom-1);
pDC->SelectObject(&p1);
pDC->LineTo(r.left+1,r.bottom-1);
pDC->SelectObject(&p2);
pDC->LineTo(r.left+1,r.bottom-1);
pDC->LineTo(r.left+1,r.bottom-2);
pDC->LineTo(r.left,r.bottom-2);
pDC->SelectObject(&p1);
pDC->LineTo(r.left,r.top+1);
pDC->SelectObject(&p2);
pDC->LineTo(r.left,r.top+1);
pDC->LineTo(r.left+1,r.top+1);
pDC->LineTo(r.left+1,r.top);
//angoli
pDC->SetPixel(r.right-3,r.top+1,RGB(191,206,220));
pDC->SetPixel(r.right-2,r.top+2,RGB(191,206,220));
pDC->SetPixel(r.right-2,r.bottom-3,RGB(191,206,220));
pDC->SetPixel(r.right-3,r.bottom-2,RGB(191,206,220));
pDC->SetPixel(r.left+1,r.bottom-3,RGB(191,206,220));
pDC->SetPixel(r.left+2,r.bottom-2,RGB(191,206,220));
pDC->SetPixel(r.left+1,r.top+2,RGB(191,206,220));
pDC->SetPixel(r.left+2,r.top+1,RGB(191,206,220));
return TRUE;//CProgressCtrl::OnEraseBkgnd(pDC);
}
void CExtProgressCtrl::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
CProgressCtrl::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
void CExtProgressCtrl::OnNcPaint()
{
// Do not call CProgressCtrl::OnNcPaint() for painting messages
}
void CExtProgressCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect r;
GetClientRect(&r);
CGradient g1,g2,g3,g4;
// g1.SetGradientColors(RGB(171,237,172),RGB(46,211,49));
// g2.SetGradientColors(RGB(46,211,49),RGB(171,237,172));
g1.SetGradientColors(RGB(171,172,237),RGB(46,49,211));
g2.SetGradientColors(RGB(46,49,211),RGB(171,172,237));
g1.SetDirection(g1.TTB);
g2.SetDirection(g2.TTB);
g3.SetGradientColors(RGB(237,171,172),RGB(211,46,49));
g4.SetGradientColors(RGB(211,46,49),RGB(237,171,172));
g3.SetDirection(g3.TTB);
g4.SetDirection(g4.TTB);
int lower,upper,pos;
GetRange(lower,upper);
pos=GetPos();
//normalizzo il range e la posizione
int size=upper-lower;
pos=pos-lower;
int aPos=m_alertPos-lower;
float percentage=(float)pos/(float)size;
int totalCtrlSize=r.right-r.left-6; //9 pixel rimangono di spazio tra i 10 step
float progressVal=totalCtrlSize*percentage;
if((m_bLessThan && pos < aPos) || (!m_bLessThan) && (pos > aPos)){
g3.DrawLinearGradient(&dc,CRect(r.left+3,r.top+3,(int)(r.left+3+progressVal),(r.bottom-2)/2));
g4.DrawLinearGradient(&dc,CRect(r.left+3,(r.bottom-2)/2,(int)(r.left+3+progressVal),r.bottom-3));
}
else{
g1.DrawLinearGradient(&dc,CRect(r.left+3,r.top+3,(int)(r.left+3+progressVal),(r.bottom-2)/2));
g2.DrawLinearGradient(&dc,CRect(r.left+3,(r.bottom-2)/2,(int)(r.left+3+progressVal),r.bottom-3));
}
}