NumericEdit.cpp
Upload User: zhuqijet
Upload Date: 2007-01-04
Package Size: 138k
Code Size: 3k
Category:

Driver Develop

Development Platform:

Visual C++

  1. // NumericEdit.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "stdlib.h"
  5. #include "NumericEdit.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // NumericEdit
  13. CNumericEdit::CNumericEdit()
  14. {
  15.  deffmt = NULL;
  16. }
  17. CNumericEdit::CNumericEdit(LPCTSTR fmt)
  18.    {
  19.     deffmt = fmt;
  20.    }
  21.     
  22. CNumericEdit::~CNumericEdit()
  23. {
  24. }
  25. BEGIN_MESSAGE_MAP(CNumericEdit, CEdit)
  26. //{{AFX_MSG_MAP(CNumericEdit)
  27. // NOTE - the ClassWizard will add and remove mapping macros here.
  28. //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // NumericEdit message handlers
  32. /****************************************************************************
  33. *                          CNumericEdit.SetWindowText
  34. * Inputs:
  35. *       int val: Value to set
  36. * LPCTSTR fmt: Format value to use
  37. * Result: void
  38. *       
  39. * Effect: 
  40. *       Sets a representation of the numeric value to the window
  41. ****************************************************************************/
  42. void CNumericEdit::SetWindowText(int val, LPCTSTR fmt)
  43.     {
  44.      if(fmt == NULL)
  45.         { /* no explict format */
  46.  if(deffmt == NULL)
  47.    fmt = _T("%d");
  48.         else
  49.    fmt = deffmt;
  50. } /* no explict format */
  51.      CString s;
  52.      s.Format(fmt, val);
  53.      // Reduce flicker: see if we have same string; don't set text if
  54.      // strings are identical.
  55.      CString oldstr;
  56.      CEdit::GetWindowText(oldstr);
  57.      if(lstrcmp(oldstr, s) != 0)
  58. CEdit::SetWindowText(s);
  59.     }
  60. /****************************************************************************
  61. *                         CNumericEdit::GetWindowInt
  62. * Result: int
  63. *       Integer value stored in edit control
  64. ****************************************************************************/
  65. int CNumericEdit::GetWindowInt()
  66.     {
  67.      CString s;
  68.      GetWindowText(s);
  69.      int val;
  70.      // TODO: Write Hex recognition code here...
  71. #ifdef _UNICODE
  72.      val = _wtoi(s);
  73. #else
  74.      val = atoi(s);
  75. #endif
  76.      return val;
  77.     }
  78. /****************************************************************************
  79. *                             CNumericEdit::Blank
  80. * Result: void
  81. *       
  82. * Effect: 
  83. *       Blanks the contents of the control
  84. ****************************************************************************/
  85. void CNumericEdit::Blank()
  86.     {
  87.      CEdit::SetWindowText(_T(""));
  88.     }