-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlatEdit.cpp
229 lines (187 loc) · 10.5 KB
/
FlatEdit.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// FlatEdit.cpp : implementation file
//////////////////////////////////////////////////
//类名:CFlatEdit
//功能:平面编辑框显示类
//作者:徐景周(Johnny Xu, xujingzhou2016@gmail.com)
//组织:未来工作室(Future Studio)
//日期:2001.12.1
//////////////////////////////////////////////////
#include "stdafx.h"
#include "FlatEdit.h"
// Download by http://www.codefans.net
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CWinApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CFlatEdit
CFlatEdit::CFlatEdit()
{
m_clrHilite = GetSysColor(COLOR_BTNHIGHLIGHT);
m_clrShadow = GetSysColor(COLOR_BTNSHADOW);
m_clrDkShad = GetSysColor(COLOR_3DDKSHADOW);
//改变平面编辑框背景色和对话框背景色相一致
m_clrButton = RGB(160,180,220); //GetSysColor(COLOR_BTNFACE);
m_bDrawGripper = false; //是否在前面和后面画手柄
m_bDrawSeperator = false;
m_bFlatStyle = TRUE;
}
CFlatEdit::~CFlatEdit()
{
}
BEGIN_MESSAGE_MAP(CFlatEdit, CEdit)
//{{AFX_MSG_MAP(CFlatEdit)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SYSCOLORCHANGE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFlatEdit message handlers
void CFlatEdit::OnMouseMove(UINT nFlags, CPoint point)
{
SetTimer(1, 10, NULL);
CEdit::OnMouseMove(nFlags, point);
}
void CFlatEdit::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bLBtnDown = true;
CEdit::OnLButtonDown(nFlags, point);
}
void CFlatEdit::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bLBtnDown =false;
CEdit::OnLButtonUp(nFlags, point);
}
void CFlatEdit::OnTimer(UINT nIDEvent)
{
POINT pt;
GetCursorPos(&pt);
CRect rcItem;
GetWindowRect(&rcItem);
static bool bPainted = false;
if(!rcItem.PtInRect(pt)) {
KillTimer(1);
DrawEdit(FE_MOUSEOUT, m_clrDkShad, m_clrHilite);
return;
}
else {
DrawEdit(FE_MOUSEOVER, m_clrShadow, m_clrHilite);
}
CEdit::OnTimer(nIDEvent);
}
void CFlatEdit::OnPaint()
{
Default();
DrawEdit(FE_MOUSEOUT, m_clrDkShad, m_clrButton);
}
void CFlatEdit::OnSysColorChange()
{
CEdit::OnSysColorChange();
m_clrHilite = GetSysColor(COLOR_BTNHIGHLIGHT);
m_clrShadow = GetSysColor(COLOR_BTNSHADOW);
m_clrDkShad = GetSysColor(COLOR_3DDKSHADOW);
//改变平面编辑框背景色和对话框背景色相一致
m_clrButton = RGB(160,180,220); //GetSysColor(COLOR_BTNFACE);
}
void CFlatEdit::DrawEdit(int style, COLORREF clrTopLeft, COLORREF clrBottomRight)
{
CRect rcItem;
CRect rcGripper;
CRect rcSeperator;
GetClientRect(&rcItem);
GetClientRect(&rcGripper);
GetClientRect(&rcSeperator);
CDC* pDC = GetDC();
COLORREF clrBlack;
clrBlack = RGB(0, 0, 0);
if(m_bFlatStyle)
{
pDC->Draw3dRect(rcItem, clrTopLeft, clrBottomRight);
rcItem.InflateRect(1,1);
if (!IsWindowEnabled()) {
pDC->Draw3dRect(rcItem, m_clrHilite, m_clrHilite);
}
else {
pDC->Draw3dRect(rcItem, m_clrButton, m_clrButton);
}
rcItem.InflateRect(1,1);
pDC->Draw3dRect(rcItem, m_clrButton, m_clrButton);
rcItem.InflateRect(1,1);
pDC->Draw3dRect(rcItem, m_clrButton, m_clrButton);
rcItem.InflateRect(1,1);
pDC->Draw3dRect(rcItem, m_clrButton, m_clrButton);
rcItem.DeflateRect(4, 4);
if(m_bDrawGripper)
{
rcGripper.top = rcItem.top;
rcGripper.bottom = rcItem.bottom;
rcGripper.left -= 4;
rcGripper.right = rcGripper.left +2;
pDC->Draw3dRect(rcGripper, m_clrHilite, m_clrShadow);
rcGripper.left -= 3;
rcGripper.right = rcGripper.left +2;
pDC->Draw3dRect(rcGripper, m_clrHilite, m_clrShadow);
}
if(m_bDrawSeperator)
{
rcSeperator.top = rcItem.top;
rcSeperator.bottom = rcItem.bottom;
rcSeperator.left = rcItem.right + 2;
rcSeperator.right = rcSeperator.left + 2;
pDC->Draw3dRect(rcSeperator, m_clrShadow, m_clrHilite);
}
if (!IsWindowEnabled()) {
return;
}
if(style == FE_MOUSEOVER)
{
pDC->Draw3dRect(rcItem, m_clrButton, m_clrButton); //added this
rcItem.top -= 1; //added this
rcItem.left -= 1;
rcItem.bottom += 1;
rcItem.right += 1; //added this
pDC->Draw3dRect(rcItem, m_clrShadow, m_clrHilite); //was hilite, shadow
}
}
else {
pDC->Draw3dRect(rcItem, clrBlack, clrBlack);
rcItem.InflateRect(1, 1);
pDC->Draw3dRect(rcItem, clrBlack, clrBlack);
pDC->Draw3dRect(rcItem, clrBlack, clrBlack);
rcItem.InflateRect(1,1);
pDC->Draw3dRect(rcItem, m_clrButton, m_clrButton);
rcItem.InflateRect(1,1);
pDC->Draw3dRect(rcItem, m_clrButton, m_clrButton);
rcItem.DeflateRect(4, 4);
if(m_bDrawGripper)
{
rcGripper.top = rcItem.top - 2;
rcGripper.bottom = rcItem.bottom + 2;
rcGripper.left -= 6;
rcGripper.right = rcGripper.left + 2;
pDC->Draw3dRect(rcGripper, clrBlack, clrBlack);
rcGripper.left -= 3;
rcGripper.right -= 3;
pDC->Draw3dRect(rcGripper, clrBlack, clrBlack);
}
if(m_bDrawSeperator)
{
rcSeperator.top = rcItem.top - 2;
rcSeperator.bottom = rcItem.bottom + 2;
rcSeperator.left = rcItem.right + 4;
rcSeperator.right = rcSeperator.left + 2;
pDC->Draw3dRect(rcSeperator, clrBlack, clrBlack);
}
}
ReleaseDC(pDC);
}
void CFlatEdit::SetIndent(int margin)
{
SetMargins(margin, 1);
}