【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,KeyEdit.cpp,希望对大家有所帮助!
// KeyEdit.cpp : implementation file
//
#include "stdafx.h"
#include "aaa.h"
#include "KeyEdit.h"
#include "CustomGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKeyEdit
CKeyEdit::CKeyEdit()
{
IsNumber =false;
}
CKeyEdit::~CKeyEdit()
{
}
BEGIN_MESSAGE_MAP(CKeyEdit, CEdit)
//{{AFX_MSG_MAP(CKeyEdit)
ON_WM_KEYDOWN()
ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
ON_WM_KILLFOCUS()
ON_WM_CREATE()
ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
ON_WM_CHAR()
ON_WM_PAINT()
ON_WM_DRAWITEM()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeyEdit message handlers
void CKeyEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CKeyEdit::OnKillfocus()
{
}
void CKeyEdit::OnKillFocus(CWnd* pNewWnd)
{
CCustomGrid * temp = (CCustomGrid *)GetParent();
if (temp)
{
temp->DisposeEdit(true);
}
}
int CKeyEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
LOGFONT font;
font.lfHeight = -12;
font.lfWidth = 0;
font.lfItalic = 0;
font.lfStrikeOut = 0;
font.lfEscapement = 0;
font.lfUnderline = 0;
font.lfWeight = 400;
font.lfCharSet = 134;
strcpy(font.lfFaceName,"宋体");
m_font.DeleteObject();
if (m_font.CreateFontIndirect(&font))
SetFont(&m_font);
return 0;
}
void CKeyEdit::OnChange()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CEdit::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CKeyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (IsNumber)
if (((nChar <45)||(nChar>46)&&(nChar<48)||(nChar > 57))&& (nChar != 8))
nChar = 0;
else
CEdit::OnChar(nChar, nRepCnt, nFlags);
else
CEdit::OnChar(nChar, nRepCnt, nFlags);
}