etrade_edit_control.cpp
2.29 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
#include "stdafx.h"
#include "etrade_edit_control.h"
#include "resource.h"
#include "place_order_dlg.h"
IMPLEMENT_DYNAMIC( CEditBox, CEdit )
CEditBox::CEditBox()
{
m_clrFrame = RGB( 245, 108, 108 );
is_edit_red_ = false;
}
CEditBox::~CEditBox()
{
m_brushBk.DeleteObject();
}
BEGIN_MESSAGE_MAP( CEditBox, CEdit )
ON_WM_CTLCOLOR_REFLECT()
ON_WM_NCPAINT()
ON_WM_KILLFOCUS()
END_MESSAGE_MAP()
HBRUSH CEditBox::CtlColor( CDC *pDC, UINT nCtlColor )
{
if( IsWindowEnabled() ) {
m_brushBk.DeleteObject();
m_brushBk.CreateSolidBrush( m_clrBackground );
pDC->SetBkColor( m_clrBackground );
pDC->SetTextColor( m_clrText );
}
else {
m_brushBk.DeleteObject();
m_brushBk.CreateSolidBrush( m_clrDisabledBack );
pDC->SetBkColor( m_clrDisabledBack );
pDC->SetTextColor( m_clrDisabledText );
}
return (HBRUSH)m_brushBk.GetSafeHandle();
}
void CEditBox::OnNcPaint()
{
CEdit::OnNcPaint();
if (is_edit_red_)
{
CRect rcEdit;
CBrush brushOut;
CDC *pDC = GetWindowDC();
GetWindowRect(rcEdit);
ScreenToClient(&rcEdit);
rcEdit.OffsetRect(CSize(2, 2));
brushOut.CreateSolidBrush(m_clrFrame);
pDC->FrameRect(rcEdit, &brushOut);
ReleaseDC(pDC);
}
}
void CEditBox::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
int dlg_id = GetDlgCtrlID();
switch (dlg_id)
{
case IDC_EDIT_CARD:
{
CString error;
do
{
CString num;
GetWindowText(num);
if (!CheckCardNum(num))
{
error = L"¿¨ºÅ´íÎó£¡";
break;
}
CString name;
bool result = GetCardName(num, name);
if (result)
{
((PlaceOrderDlg*)GetParent())->name_edit_.SetWindowText(name);
}
else
{
error = name;
}
} while (0);
if (!error.IsEmpty())
{
SetEditRed(true);
}
else
{
SetEditRed(false);
}
((PlaceOrderDlg*)GetParent())->error_static_.SetWindowText(error);
UpdateWindow();
break;
}
case IDC_EDIT_COMM_NUM:
{
break;
}
}
}
bool CEditBox::CheckCardNum(CString &num)
{
bool result = true;
do
{
if (num.GetLength() != 12)
{
result = false;
break;
}
if (num.SpanIncluding(L"0123456789") != num)
{
result = false;
break;
}
} while (0);
return result;
}
bool CEditBox::GetCardName(CString &num, CString &name)
{
bool result = true;
return result;
}
void CEditBox::SetEditRed(bool is_red)
{
is_edit_red_ = is_red;
}