123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include "StdAfx.h"
- #include "RuleEdit.h"
- #define MAX_INPUTCHAR 24
- CRuleEdit::CRuleEdit(void)
- {
- }
- CRuleEdit::~CRuleEdit(void)
- {
- }
- BEGIN_MESSAGE_MAP(CRuleEdit, CEdit)
- ON_WM_CHAR()
- END_MESSAGE_MAP()
- //-------------------------------------------------------------
- // 说明:
- // 处理的字符:
- // 数字、字母、下划线、横线。
- // 长度限制:最大输入数MAX_INPUTCHAR;
- //-------------------------------------------------------------
- void CRuleEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // 退格符要优先执行;
- if (nChar == 8 )
- CEdit::OnChar(nChar, nRepCnt, nFlags);
- int nStart, nEnd;
- CString strContext;
- GetWindowText(strContext);
- GetSel(nStart, nEnd);
- //if ( (nEnd-nStart) < MAX_INPUTCHAR && (strContext.GetLength() >= MAX_INPUTCHAR || nStart > MAX_INPUTCHAR ))
- if ( (nEnd-nStart) < MAX_INPUTCHAR && strContext.GetLength() >= MAX_INPUTCHAR)
- {
- return;
- }
-
- if (nChar == '-' || nChar == '_' || (nChar >=48 && nChar <= 57) || (nChar >=65 && nChar <= 90) || (nChar >= 97 && nChar <= 122))
- {
- CEdit::OnChar(nChar, nRepCnt, nFlags);
- }
- }
|