-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCEditEx.cpp
More file actions
170 lines (145 loc) · 6.51 KB
/
Copy pathCEditEx.cpp
File metadata and controls
170 lines (145 loc) · 6.51 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
// CEditEx.cpp : 实现文件
//
#include "pch.h"
#include "CEditEx.h"
// CCEditEx
IMPLEMENT_DYNAMIC(CCEditEx, CStatic)
CCEditEx::CCEditEx()
{
m_normal_in_color = RGB(241,241,241);
m_normal_out_color = RGB(241,241,241);
m_bkColor = m_normal_in_color;
m_text_color = RGB(0,0,0);
m_radian = 10;
m_padding = 20;
m_bkBrush.CreateSolidBrush(m_normal_in_color);
m_strTip = "";
m_bPwdInput = FALSE;
m_bDisable = FALSE;
}
CCEditEx::~CCEditEx()
{
}
BEGIN_MESSAGE_MAP(CCEditEx, CStatic)
ON_WM_NCPAINT()
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CCEditEx 消息处理程序
void CCEditEx::PreSubclassWindow()
{
DWORD dwStyle = GetStyle();
SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_OWNERDRAW | SS_NOTIFY);
CStatic::PreSubclassWindow();
}
void CCEditEx::OnNcPaint()
{
CStatic::OnNcPaint();
}
void CCEditEx::OnPaint()
{
CStatic::OnPaint();
}
void CCEditEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CRect rc;
rc = lpDrawItemStruct->rcItem;
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
dc.SelectObject(&m_bkBrush);
DrawBorder(&dc,rc);
rc.DeflateRect(m_padding, m_padding);
if (m_edit.GetSafeHwnd() && !m_bDisable)
{
m_edit.ShowWindow(SW_SHOW);
m_edit.SetBkColor(m_bkColor);
m_edit.SetWindowText(m_strText);
}
else if(m_edit.GetSafeHwnd() && m_bDisable)
{
m_edit.EnableWindow(FALSE);
m_edit.SetBkColor(m_bkColor);
m_edit.SetWindowText(m_strText);
}
else
{
GetClientRect(&rc);
rc.DeflateRect(10,10);
m_edit.Create(WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL, rc, this, 1);
m_edit.SetFont(GetFont());
//m_edit.SetCueBanner("123");
if(m_bPwdInput){
m_edit.SetPasswordChar('*');
}
m_edit.SetWindowText(m_strText);
m_edit.SetBkColor(m_bkColor);
m_edit.ShowWindow(SW_SHOW);
if(m_bDisable)
{
m_edit.EnableWindow(FALSE);
}
}
ReleaseDC(&dc);
}
void CCEditEx::DrawBorder(CDC* dc,CRect &rc) {
CPen inpen(PS_SOLID, 1, m_normal_out_color);
CPen outpen(PS_SOLID, 1, m_normal_in_color);
CPen * oldPen = dc->SelectObject(&inpen);
dc->RoundRect(rc, CPoint(m_radian, m_radian));
rc.InflateRect(-1, -1);
dc->SelectObject(&outpen);
dc->RoundRect(rc, CPoint(m_radian, m_radian));
dc->SelectObject(oldPen);
oldPen->Detach();
oldPen = NULL;
}
void CCEditEx::setTipText(CString tip)
{
m_strTip = tip;
InvalidateRect(NULL);
}
void CCEditEx::SetBkColor(COLORREF color)
{
m_bkColor = color;
m_bkBrush.DeleteObject();
m_bkBrush.CreateSolidBrush(color);
if(m_edit.GetSafeHwnd())
{
m_edit.SetBkColor(color);
}
Invalidate(TRUE);
}
void CCEditEx::SetBorderColor(COLORREF color)
{
}
void CCEditEx::setPwdMode(BOOL bPwdMode)
{
m_bPwdInput = bPwdMode;
}
void CCEditEx::SetWindowText(CString strText)
{
m_strText = strText;
Invalidate(TRUE);
}
void CCEditEx::GetWindowText(CString& strText)
{
m_edit.GetWindowText(strText);
}
BOOL CCEditEx::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
CCustomDrawEdit& CCEditEx::GetMyEdit()
{
return m_edit;
}
void CCEditEx::SetDisable(BOOL isDisable)
{
m_bDisable = isDisable;
Invalidate(TRUE);
}
HBRUSH CCEditEx::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CStatic::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}