| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- #pragma once
- #include "MaskEditT.h"
- //===========================================================================
- // Summary:
- // CMaskEdit is a CEdit derived class. It allows text masking to be
- // applied to the control to format it for special editing restrictions.
- //===========================================================================
- class CMaskEdit : public CMaskEditT<CEdit>
- {
- DECLARE_DYNAMIC(CMaskEdit)
- public:
- //-----------------------------------------------------------------------
- // Summary:
- // Constructs a CMaskEdit object
- //-----------------------------------------------------------------------
- CMaskEdit();
- public:
- //-----------------------------------------------------------------------
- // Summary:
- // This member function will set the mask for the edit control.
- // Parameters:
- // lpszMask - The format for the mask field. For example, if
- // you wanted to set the mask for a phone number,
- // and you only wanted digits to be entered, your
- // mask might look like this; _T("(000) 000-0000").
- // lpszLiteral - The literal format is entered here. Wherever you
- // place an underscore ('_') is where the user will
- // be allowed to enter data only. Using the phone
- // number example; _T("(___) ___-____").
- // lpszDefault - Text that is to be displayed when the control
- // is initialized. For example; _T("(800) 555-1212").
- // If NULL, 'lpszLiteral' is used to initialize the
- // edit text.
- // Remarks:
- // The values that can be set are:
- // Mask Character Description
- // --------------------- ------------------------
- // 0 Numeric (0-9)
- // 9 Numeric (0-9) or space (' ')
- // # Numeric (0-9) or space (' ') or ('+') or ('-')
- // L Alpha (a-Z)
- // ? Alpha (a-Z) or space (' ')
- // A Alpha numeric (0-9 and a-Z)
- // a Alpha numeric (0-9 and a-Z) or space (' ')
- // & All print character only
- // H Hex digit (0-9 and A-F)
- // X Hex digit (0-9 and A-F) and space (' ')
- // > Forces characters to upper case (A-Z)
- // < Forces characters to lower case (a-z)
- //-----------------------------------------------------------------------
- virtual void SetEditMask(LPCTSTR lpszMask,LPCTSTR lpszLiteral,LPCTSTR lpszDefault=NULL);
- protected:
- DECLARE_MESSAGE_MAP()
- };
- //===========================================================================
- // Summary:
- // CDateEdit is a CMaskEdit derived class. It is specifically
- // geared toward editing date fields.
- //===========================================================================
- class CDateEdit : public CMaskEdit
- {
- DECLARE_DYNAMIC(CDateEdit)
- public:
- //-----------------------------------------------------------------------
- // Summary:
- // Constructs a CDateEdit object
- //-----------------------------------------------------------------------
- CDateEdit();
- //-----------------------------------------------------------------------
- // 用途:
- // 把COleDateTime对象中的日期部分转换成文本
- // 参数:
- // dt - COleDateTime对象
- // 返回值:
- // 日期文本,例如“2005-09-06”。如果参数dt不是合法的对象,则返回缺省
- // 值“1899-12-30”
- //-----------------------------------------------------------------------
- static CString DateToString(COleDateTime dt);
- //-----------------------------------------------------------------------
- // 用途:
- // 把日期/时间文本转换成COleDateTime对象
- // 参数:
- // strText - 日期/时间文本
- // chPrompt - 格式化输入的提示字符
- // 返回值:
- // COleDateTime对象。如果文本格式不对,返回的COleDateTime对象不是一个
- // 合法的对象。
- //-----------------------------------------------------------------------
- static COleDateTime StringToOleDateTime(CString strText, TCHAR chPrompt = _T('_'));
- //-----------------------------------------------------------------------
- // 用途:
- // 设置控件的日期。
- // 参数:
- // dt - COleDateTime对象,只用到日期部分。构造对象时要注意,虽然没用到
- // 时间部分,也要赋一个合法的时间,否则得到的对象是不合法的。
- //-----------------------------------------------------------------------
- virtual void SetDateTime(COleDateTime dt);
- //-----------------------------------------------------------------------
- // 用途:
- // 从控件文本获取日期/时间。
- // 返回值:
- // COleDateTime对象。如果文本格式不对,返回的COleDateTime对象不是一个
- // 合法的对象。
- //-----------------------------------------------------------------------
- COleDateTime GetDateTime();
- //-----------------------------------------------------------------------
- // Summary:
- // This member function is used internally to process the character passed
- // in by 'nChar' whose index is specified by 'nEndPos'.
- // Parameters:
- // nChar - Contains the character code value of the key.
- // nEndPos - Index of character in display string.
- // Returns:
- // TRUE if successful, otherwise returns FALSE.
- //-----------------------------------------------------------------------
- virtual BOOL ProcessMask(UINT& nChar, int nEndPos);
- };
- // ----------------------------------------------------------------------------
- // Summary:
- // The DDX_OleDateTime function manages the transfer of
- // integer data between a date edit control, in a dialog box, form
- // view, or control view object, and a COleDateTime data member of
- // the dialog box, form view, or control view object.
- //
- // When DDX_OleDateTime is called, 'value' is set to
- // the current state of the date edit control.
- // Parameters:
- // pDX - A pointer to a CDataExchange object. The framework supplies
- // this object to establish the context of the data exchange,
- // including its direction.
- // nIDC - The resource ID of the date edit control associated with the
- // control property.
- // rDateTime - A reference to a member variable of the dialog box, form
- // view, or control view object with which data is exchanged.
- // See Also:
- // CDateEdit
- // ----------------------------------------------------------------------------
- void AFXAPI DDX_OleDateTime(CDataExchange* pDX, int nIDC, COleDateTime& rDateTime);
- //===========================================================================
- // Summary:
- // CTimeEdit is a CDateEdit derived class. It is specifically geared
- // toward editing time fields.
- //===========================================================================
- class CTimeEdit : public CDateEdit
- {
- DECLARE_DYNAMIC(CTimeEdit)
- public:
- //-----------------------------------------------------------------------
- // 用途:
- // 构造函数。
- // 参数:
- // bHasSecond - 表明是否包含“秒”
- //-----------------------------------------------------------------------
- CTimeEdit(BOOL bHasSecond = FALSE);
- public:
- //-----------------------------------------------------------------------
- // 用途:
- // 把COleDateTime对象中的时间部分转换成文本
- // 参数:
- // dt - COleDateTime对象
- // bHasSecond - 表明是否包含“秒”
- // 返回值:
- // 时间文本,例如“15:39”。如果参数dt不是合法的对象,则返回缺省值
- // “00:00”
- //-----------------------------------------------------------------------
- static CString TimeToString(COleDateTime dt, BOOL bHasSecond = FALSE);
- //-----------------------------------------------------------------------
- // 用途:
- // 设置控件的时间。
- // 参数:
- // dt - COleDateTime对象,只用到时间部分。构造对象时要注意,虽然没用到
- // 日期部分,也要赋一个合法的年月日,否则得到的对象是不合法的。
- //-----------------------------------------------------------------------
- virtual void SetDateTime(COleDateTime dt);
- //-----------------------------------------------------------------------
- // Summary:
- // This member function is used internally to process the character
- // passed in by 'nChar' whose index is specified by 'nEndPos'.
- // Parameters:
- // nChar - Contains the character code value of the key.
- // nEndPos - Index of the character in the display string.
- // Returns:
- // TRUE if successful, otherwise returns FALSE.
- //-----------------------------------------------------------------------
- virtual BOOL ProcessMask(UINT& nChar, int nEndPos);
- protected:
- BOOL m_bHasSecond; // 表明是否包含“秒”
- };
- //===========================================================================
- // 用途:
- // CDegreeEdit 派生自 CMaskEdit,以度分秒的形式输入度,秒的小数点后的位数
- // 在构造对象时确定。有效输入范围是-999度至999度
- // 作者:
- // 祝晓鹰
- //===========================================================================
- class CDegreeEdit: public CMaskEdit
- {
- DECLARE_DYNAMIC(CDegreeEdit)
- public:
- //-----------------------------------------------------------------------
- // 用途:
- // 构造函数
- // 参数:
- // nSecondPrecision - 指示秒的小数点后保留几位,范围0-3,缺省为两位
- //-----------------------------------------------------------------------
- CDegreeEdit(int nSecondPrecision = 2);
- public:
- //-----------------------------------------------------------------------
- // 用途:
- // 以浮点数形式设置度,控件将用度分秒的形式表示出来
- // 参数:
- // fDegree - 浮点数形式的度
- //-----------------------------------------------------------------------
- void SetDegree(double fDegree);
- //-----------------------------------------------------------------------
- // 用途:
- // 以浮点数的形式返回用户在控件中输入的度
- // 返回值:
- // 浮点数形式的度
- //-----------------------------------------------------------------------
- double GetDegree();
- //-----------------------------------------------------------------------
- // 用途:
- // 把浮点数形式的度转换成度分秒格式的文本
- // 参数:
- // fDegree - 浮点数形式的度
- // nSecondPrecision - 指示秒的小数点后保留几位,范围0-3
- // 返回值:
- // 度分秒格式的文本。例如当秒保留两位小数时,-10.13度转换成文本后内容
- // 为“- 10°07'48.00"”。注意符号位和度之间可能存在空格,如果打算用
- // 诸如sscanf这样的函数从转换后的文本中提取数据,需要先删除空格。
- //-----------------------------------------------------------------------
- static CString DegreeToString(double fDegree, int nSecondPrecision = 2);
- //-----------------------------------------------------------------------
- // 用途:
- // 把度分秒格式的文本转换成浮点数形式的度
- // 参数:
- // strText - 度分秒格式的文本
- // 返回值:
- // 浮点数形式的度
- //-----------------------------------------------------------------------
- static double StringToDegree(CString strText);
- protected:
- int m_nSecondPrecision; // 秒的小数部分的位数,范围0-3
- };
- // ----------------------------------------------------------------------------
- // 用途:
- // 函数DDX_Degree用来在一个浮点型的对话框成员变量和度编辑控件之间交换数据。
- // 参数:
- // pDX - 由系统提供的一个CDataExchange对象指针
- // nIDC - 控件ID
- // value - 以浮点数的形式返回控件中的度
- // 作者:
- // 祝晓鹰
- // ----------------------------------------------------------------------------
- void AFXAPI DDX_Degree(CDataExchange* pDX, int nIDC, double& value);
|