-
Notifications
You must be signed in to change notification settings - Fork 1
/
StatusBarEx.cpp
202 lines (152 loc) · 5.42 KB
/
StatusBarEx.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
199
200
201
202
// CedtStatusBar.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "StatusBarEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PANE_WIDTH_PROGRESS 200
/////////////////////////////////////////////////////////////////////////////
// CStatusBarEx
CStatusBarEx::CStatusBarEx()
{
m_fontPane1.CreateStockObject( ANSI_VAR_FONT );
m_fontPane2.CreateStockObject( DEFAULT_GUI_FONT );
memset( m_crPaneTextColors, 0x00, sizeof(m_crPaneTextColors));
memset( m_bPaneHighlight, 0x00, sizeof(m_bPaneHighlight));
}
CStatusBarEx::~CStatusBarEx()
{
m_fontPane1.DeleteObject();
m_fontPane2.DeleteObject();
}
BEGIN_MESSAGE_MAP(CStatusBarEx, CStatusBar)
//{{AFX_MSG_MAP(CStatusBarEx)
ON_WM_PAINT()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatusBarEx message handlers
int CStatusBarEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatusBar::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CStatusBarEx::BeginProgress(LPCTSTR lpszMessage)
{
CStatusBar::SetPaneText(0, "", FALSE);
m_szPaneText = lpszMessage;
}
void CStatusBarEx::EndProgress()
{
CString szPaneText( (LPCTSTR)AFX_IDS_IDLEMESSAGE );
CStatusBar::SetPaneText(0, szPaneText, FALSE);
m_szPaneText = szPaneText;
Invalidate();
}
void CStatusBarEx::SetProgress(INT nPercent)
{
CFont * pFontOld; CBitmap * pBmpOld;
CRect rect; GetItemRect(0, & rect);
rect.right = rect.left + PANE_WIDTH_PROGRESS;
CDC * pDC = GetDC();
m_dcPane.CreateCompatibleDC( pDC );
m_dcPane.SetBkMode(TRANSPARENT);
pFontOld = m_dcPane.SelectObject( & m_fontPane1 );
m_bmpPane.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() );
pBmpOld = m_dcPane.SelectObject( & m_bmpPane );
// draw border
CRect border; border.left = border.top = 0;
border.right = rect.Width();
border.bottom = rect.Height();
DrawPaneBorder( & m_dcPane, border );
// draw pane
CString szPaneText; szPaneText.Format("%s %i%%", m_szPaneText, nPercent);
DrawPaneText( & m_dcPane, border, szPaneText, RGB(0, 0, 0) );
INT nSplit = border.Width() * nPercent / 100;
m_dcPane.ExcludeClipRect(nSplit, 0, rect.Width(), rect.Height());
m_dcPane.FillSolidRect(1, 1, border.Width()-2, border.Height()-2, RGB(0, 0, 180));
DrawPaneText( & m_dcPane, border, szPaneText, RGB(255, 255, 255) );
// bit built
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
& m_dcPane, 0, 0, SRCCOPY);
m_dcPane.SelectObject( pFontOld );
m_dcPane.SelectObject( pBmpOld );
m_bmpPane.DeleteObject();
m_dcPane.DeleteDC();
ReleaseDC( pDC );
}
void CStatusBarEx::SetPaneTextColor(INT nIndex, COLORREF crTextColor)
{
if( m_crPaneTextColors[nIndex] == crTextColor ) return;
m_crPaneTextColors[nIndex] = crTextColor;
CRect rect; GetItemRect(nIndex, & rect);
InvalidateRect(& rect, FALSE);
}
void CStatusBarEx::SetPaneHighlight(INT nIndex, BOOL bHighlight)
{
if( m_bPaneHighlight[nIndex] == bHighlight ) return;
m_bPaneHighlight[nIndex] = bHighlight;
CRect rect; GetItemRect(nIndex, & rect);
InvalidateRect(& rect, FALSE);
}
void CStatusBarEx::OnPaint()
{
CStatusBar::OnPaint(); // call parent class OnPaint member function
CRect rect; GetClientRect( & rect );
CDC * pDC = GetDC();
m_dcPane.CreateCompatibleDC( pDC );
m_dcPane.SetBkMode(TRANSPARENT);
CFont * pFontOld = m_dcPane.SelectObject( & m_fontPane2 );
m_bmpPane.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() );
CBitmap * pBmpOld = m_dcPane.SelectObject( & m_bmpPane );
CStatusBarCtrl & rStatusBarCtrl = GetStatusBarCtrl();
INT nCount = rStatusBarCtrl.GetParts(0, NULL);
for(INT nPane = 1; nPane < nCount; nPane++) {
GetItemRect(nPane, & rect);
CRect border; border.left = border.top = 0;
border.right = rect.Width();
border.bottom = rect.Height();
COLORREF crBgColor = m_bPaneHighlight[nPane] ? m_crPaneTextColors[nPane] : GetSysColor(COLOR_3DFACE);
m_dcPane.FillSolidRect( & border, crBgColor);
CString szPaneText; GetPaneText(nPane, szPaneText);
COLORREF crTextColor = m_bPaneHighlight[nPane] ? GetSysColor(COLOR_3DFACE) : m_crPaneTextColors[nPane];
DrawPaneText( & m_dcPane, border, szPaneText, crTextColor );
pDC->BitBlt(rect.left+1, rect.top+1, rect.Width()-2, rect.Height()-2, & m_dcPane, 1, 1, SRCCOPY);
}
m_dcPane.SelectObject( pFontOld );
m_dcPane.SelectObject( pBmpOld );
m_bmpPane.DeleteObject();
m_dcPane.DeleteDC();
ReleaseDC( pDC );
}
void CStatusBarEx::DrawPaneBorder(CDC * pDC, CRect rect)
{
CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
CPen * pPenOld;
pPenOld = pDC->SelectObject( & penShadow );
pDC->MoveTo(rect.right-2, rect.top);
pDC->LineTo(rect.left, rect.top);
pDC->LineTo(rect.left, rect.bottom-2);
pDC->SelectObject( & penLight );
pDC->MoveTo(rect.left, rect.bottom-1);
pDC->LineTo(rect.right-1, rect.bottom-1);
pDC->LineTo(rect.right-1, rect.top);
pDC->FillSolidRect(rect.left+1, rect.top+1, rect.right-2, rect.bottom-2, GetSysColor(COLOR_3DFACE));
pDC->SelectObject( pPenOld );
}
void CStatusBarEx::DrawPaneText(CDC * pDC, CRect rect, LPCTSTR lpszPaneText, COLORREF crTextColor)
{
INT nLength = strlen(lpszPaneText);
CSize size = pDC->GetTextExtent(lpszPaneText, nLength);
INT nPosX = rect.left + (rect.Width() - size.cx) / 2;
INT nPosY = rect.top + (rect.Height() - size.cy) / 2;
pDC->SetTextColor(crTextColor);
pDC->TextOut(nPosX, nPosY, lpszPaneText, nLength);
}