RuleEdit.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "StdAfx.h"
  2. #include "RuleEdit.h"
  3. #define MAX_INPUTCHAR 24
  4. CRuleEdit::CRuleEdit(void)
  5. {
  6. }
  7. CRuleEdit::~CRuleEdit(void)
  8. {
  9. }
  10. BEGIN_MESSAGE_MAP(CRuleEdit, CEdit)
  11. ON_WM_CHAR()
  12. END_MESSAGE_MAP()
  13. //-------------------------------------------------------------
  14. // 说明:
  15. // 处理的字符:
  16. // 数字、字母、下划线、横线。
  17. // 长度限制:最大输入数MAX_INPUTCHAR;
  18. //-------------------------------------------------------------
  19. void CRuleEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  20. {
  21. // 退格符要优先执行;
  22. if (nChar == 8 )
  23. CEdit::OnChar(nChar, nRepCnt, nFlags);
  24. int nStart, nEnd;
  25. CString strContext;
  26. GetWindowText(strContext);
  27. GetSel(nStart, nEnd);
  28. //if ( (nEnd-nStart) < MAX_INPUTCHAR && (strContext.GetLength() >= MAX_INPUTCHAR || nStart > MAX_INPUTCHAR ))
  29. if ( (nEnd-nStart) < MAX_INPUTCHAR && strContext.GetLength() >= MAX_INPUTCHAR)
  30. {
  31. return;
  32. }
  33. if (nChar == '-' || nChar == '_' || (nChar >=48 && nChar <= 57) || (nChar >=65 && nChar <= 90) || (nChar >= 97 && nChar <= 122))
  34. {
  35. CEdit::OnChar(nChar, nRepCnt, nFlags);
  36. }
  37. }