-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatusBarEx.cpp
More file actions
91 lines (76 loc) · 1.91 KB
/
StatusBarEx.cpp
File metadata and controls
91 lines (76 loc) · 1.91 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
// StatusBarEx.cpp : implementation file
//
#include "stdafx.h"
#include "StatusBarEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStatusBarEx
CStatusBarEx::CStatusBarEx()
{
m_pColor=NULL;
}
CStatusBarEx::~CStatusBarEx()
{
}
BEGIN_MESSAGE_MAP(CStatusBarEx, CStatusBar)
//{{AFX_MSG_MAP(CStatusBarEx)
ON_WM_PAINT()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatusBarEx message handlers
void CStatusBarEx::OnPaint()
{
//如果用户没有设置颜色,就调用CStatusBar::OnPaint();
if(m_pColor==NULL)
{
CStatusBar::OnPaint();
return;
}
PAINTSTRUCT ps;
CDC* pDC = BeginPaint(&ps);
// TODO: Add your message handler code here
//自定义绘制CStatusBar的每一个文本框
CRect rect;
COLORREF hell = GetSysColor(COLOR_3DHILIGHT);
COLORREF dunkel = GetSysColor(COLOR_3DSHADOW);
int oldMode=pDC->SetBkMode(TRANSPARENT);
CFont font,*pOldFont;
font.CreatePointFont(100,_T("宋体"));
pOldFont=pDC->SelectObject(&font);
int i;
for(i=0;i<m_nCount;i++)
{
GetItemRect(i,&rect);
pDC->FillSolidRect(rect,::GetSysColor(COLOR_BTNFACE));
pDC->Draw3dRect(rect, dunkel, hell);
rect=CRect(rect.left,rect.top,rect.right,rect.bottom);
COLORREF oldColor=pDC->SetTextColor(m_pColor[i]);
rect.top +=2;
pDC->DrawText(GetPaneText(i),&rect,DT_LEFT);
pDC->SetTextColor(oldColor);
}
pDC->SetBkMode(oldMode);
pDC->SelectObject(pOldFont);
EndPaint(&ps);
// Do not call CStatusBar::OnPaint() for painting messages
}
void CStatusBarEx::SetTextColor(int index,COLORREF color)
{
int i;
if(m_pColor==NULL)
{
m_pColor=new COLORREF[m_nCount];
for(i=0;i<m_nCount;i++)
{
m_pColor[i]=RGB(0,0,0);
}
}
m_pColor[index]=color;
::RedrawWindow(m_hWnd,NULL,NULL,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
}