etrade_edit_control.cpp 2.29 KB
#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;
}