锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 英语翻译 / 开源技术 / VC++和MFC高级控件带格式化功能的编辑控件ValidatingEditControls(如需技术支持,联系QQ)
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
技术分类
讨论组翻译
时间编辑框
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。

对应英文网页为http://www.codeproject.com/Articles/5015/Validating-Edit-Controls
Edit主界面

个人应用心得

本CEdit能够格式化数字文本的输入,比如限定小数点后位个数和输入总长度等等。下面是简要的使用说明:
绑定控件变量类型到CAMSNumericEdit,它的值通过如下语句来获取:
m_dEditNumericAsDouble = m_ctlEditNumericDataEntry.GetDouble();

在对话框的OnInitDialog里初始化
// Allow automatic input of the decimal after the maximum number of whole digits has been entered
m_ctlEditNumericDataEntry.ModifyFlags(CAMSNumericEdit::AddDecimalAfterMaxWholeDigits, 0);

是否允许负值

m_ctlEditNumericDataEntry.AllowNegative(FALSE);

设置小数点前宽度
m_ctlEditNumericDataEntry.SetMaxWholeDigits(m_nEditNumericLeftDigits);

设置小数点后宽度

m_ctlEditNumericDataEntry.SetMaxDecimalPlaces(m_nEditNumericRightDigits);

导航

介绍

Edit controls are often used to enter dates, times, currency values, or preformatted numeric data such as phone numbers. A control that allows its user to only enter a specific type of data is useful for several reasons:

  1. The user may do less typing if the control automatically fills in characters such as dashes or slashes.
  2. The user gets immediate feedback if he/she enters an invalid character.
  3. The entered data is much more likely to be valid when the user "submits" it.

The classes presented in this article provide these benefits for the most popular types of data that may be entered: dates, times, decimals, integers, currency amounts, formatted numerics, and restricted alphanumerics.
编辑控件通常用于输入日期、时间、货币值,或预格式化的数值数据,如电话号码。使用户只输入一个特定类型的数据,这样的控制是有用的,有以下几个原因:

  1. 如果控制自动填充字符如破折号或斜线,用户可能会少打些字。
  2. 如果他/她输入一个无效字符,用户得到即时反馈。
  3. 当用户“提交”输入时,输入的数据更可能是有效的。

对于最常用的数据类型的输入,本文中提出的类有很多优点,数据类型支持:日期、时间、小数、整数、货币金额、格式化的数值,并限制字母和数字。

背景

A while back I worked on a project which required edit controls with very strict behavior. One was a date control which needed to accept dates in mm/dd/yyyy format only. The user would be allowed to enter just the numbers and the slashes would be filled in automatically (unlike Microsoft’s Date control). The control would also prevent the user from messing up the format, by, for example, deleting the second character. Another edit control was used for entering dollar amounts and would automatically insert commas for the thousand’s separator.
I went on the hunt for a set of controls that would give me this behavior and I took a look at Masked Edit Control from Dundas Software. Unfortunately it wasn’t specific enough, especially when it came to dates. I needed more than just a masked control; I needed to make sure the value would always be valid. I also didn’t feel like spending time modifying or extending Dundas’s code to make it work like I needed it, so I took a big gulp and decided to do it all from scratch. What you see now is the result of that effort, which I finally got around to publishing. :-)
前阵子我曾在一个项目,要实现行为非常严格的编辑控件。一个是日期的控制,只接受MM / DD / YYYY格式的日期。用户只允许输入数字,斜线将自动填充(不像微软的日期控制)。做好控制,防止用户搞乱了格式,例如,删去第二个字符。另一个编辑控件用于输入美元金额,并会自动插入逗号千元分隔符。
我搜索了一套有这种能力的控件,我从Dundas软件公司查到了格式编辑控件,不幸的是,它不够具体,特别是当它处理日期时。我需要的不仅仅是一个掩码控制,我需要确保的值永远是有效的。我也不想花时间修改或扩展登打士的控件来达到我的目的,所以我花了大把时间,并决定这一切从头开始做。你现在看到的是这种努力的结果,我终于得到了成功发布。:-)

All classes derive from CEdit and are prefixed with CAMS (AMS are my company’s initials). The following table gives the class names and descriptions:
所有类从CEdit的派生和带上CAMS前缀(AMS是我公司的缩写)。下表给出了类的名称和描述:


类的名称

描述

CAMSEdit

下面的类的基类。它有一些基本的功能。

CAMSAlphanumericEdit

禁止输入一个或多个字符,并限制长度。

CAMSNumericEdit

提供对小数点前/后数字最大个数限制的十进制输入功能。

CAMSIntegerEdit

只允许输入整数。

CAMSCurrencyEdit

以货币符号开始和带千位分隔的编辑框。

CAMSDateEdit

依赖本地化环境,输入mm/dd / yyyy或dd/mm/yyyy格式的日期控件。

CAMSTimeEdit

依赖本地化环境,允许带或不带秒,以12或24小时格式输入时的控件。

CAMSDateTimeEdit

允许输入日期和时间,结合上述两个类。

CAMSMaskedEdit

使用掩码“#”符号,每一个对应一个数字。用户在#之间输入的任何字符自动插入。它可以定制接受其它的符号。

CAMSMultiMaskedEdit

使用掩码,并采用以上述任何一个类能力的控件。

What follows is a more detailed description of these classes and their usage. All member functions are public unless otherwise specified.下面是一个对这些类和它们的用法更详细的说明。所有成员函数都是公开的,除非另有规定。

CAMSEdit

I decided to give all my CEdit-derived classes a common base class for any common methods they may need. The result is this class which only has minor enhancements to the CEditclass, but serves as a pseudo-namespace for the Behavior classes used by the CAMSEdit-derived classes.我决定写个通用基类,把任何常用的需要的方法放到基类里。结果是这个基类相对CEdit变动很小,但作为伪命名空间服务于行为类让 CAMSEdit派生类来用。


成员

描述

void SetText(const CString& strText)

设置控件的文本。以控件合适格式验证文本。

CString GetText() const

获取控件文本。

CString GetTrimmedText() const

以去掉前导或尾随空格方式获取控件中的文本。

void SetBackgroundColor(COLORREF rgb)

设置控件的背景颜色。

COLORREF GetBackgroundColor() const

获取控件的背景颜色。

void SetTextColor(COLORREF rgb)

设置控件的文本颜色。

COLORREF GetTextColor() const

获取控件的文本颜色。

bool IsReadOnly() const

如果控件只读,则返回true。

virtual bool ShouldEnter(TCHAR c) const;

This protected member is called directly by all classes right before a typed-in character is to be shown. By default it always returns true. But you may override it (in a derived class) and make it return false if the user enters a character you don't want to allow.
在输入的字符显示前,就在这个时刻,这个受保护的成员函数会被所有类直接调用。默认情况下,它总是返回true。如果用户输入的字符是你不允许的,但你可能会覆盖(在派生类里),并使其返回false。

CAMSAlphanumericEdit

This class is used for general alphanumeric input with the exception of whatever characters you specify to not be allowed. So if you need to prevent certain characters from being entered, this class is useful. It can also restrict the length of the text.这个类用于一般字母数字的输入,可指定例外的字符。所以,如果你需要防止某些字符输入,这个类是有用的。它也可以限制文本的长度。


成员

描述

void SetInvalidCharacters(const CString& strInvalidChars)

Sets each of characters contained in the given string to not be allowed for input. By default these characters are not allowed: %'*"+?><:\
设置不允许输入字符串,当输入字符串中的任何一个时,都输入不了。默认情况下,这些字符是不允许的: %“*”+“<\

const CString& GetInvalidCharacters() const

获取不允许输入的字符。

void SetMaxCharacters(int nMaxChars)

设置允许的最大字符数。默认情况下是没有限制(0)。

int GetMaxCharacters() const

获取允许的最大字符数。

CAMSNumericEdit
This is the base class for all numeric entry classes. It ensures that the user enters a valid number and provides features such as automatic formatting. It also allows you to restrict what the number can look like, such as how many digits before and after the decimal point, and whether it can be negative or not.
这是所有数字输入类的基类。它确保用户输入一个有效的数字,并提供功能,如自动格式化。它还允许你限制输入轮廓,比如小数点后多少位和前面多少位,是否可以为负数或不是。


成员

描述

void SetDouble(double dText,
 boolbTrimTrailingZeros = true)

Sets the control's text to the given double value. If bTrimTrailingZeros is true, any insignificant zeros after the decimal point are removed.
设置控件的文本为给定的浮点值。如果 bTrimTrailingZeros是真实的,小数点后的任何无意义的零被删除。

double GetDouble() const

以double类型返回当前文本。

void SetInt(int nText)

设置控件的文本为给定的整型值。

int GetInt() const

以整型值返回当前文本。

void SetMaxWholeDigits(int 
nMaxWholeDigits)

设置小数点前的最大位数。默认情况为9。

int GetMaxWholeDigits() const

获取小数点前的最大位数。

void SetMaxDecimalPlaces(int 
nMaxDecimalPlaces)

设置小数点后的最大位数。默认情况为4。

int GetMaxDecimalPlaces() const

获取小数点后最大位数。

void AllowNegative(bool bAllowNegative = true)

设置一个标志指示是否允许负数符号。默认情况下,是允许的。

bool IsNegativeAllowed() const

确定是否可以输入负数符号。

void SetDigitsInGroup(int 
nDigitsInGroup)

Sets the size of the groups of digits to be separated before the decimal point. This is 0 by default but is typically set to 3 to separate thousands.
设置小数点之前分隔的数字组的大小。这是默认为0,但通常被设置为3来分隔千。

int GetDigitsInGroup() const

获取小数点前显示数字组的个数。

void SetSeparator(TCHAR cDecimal, TCHAR cGroup)

设置小数点使用字符和组分隔(千)使用字符

void GetSeparator(TCHAR* pcDecimal, TCHAR* pcGroup) const

获取小数点和组分隔符(千)所使用的字符。

void SetPrefix(const CString& strPrefix)

设置输入而自动显示数字值前面的字符。用于显示货币符号。默认情况下它是空的。

const CString& GetPrefix() const

获取显示在输入数字值前面的自动字符。

void SetMask(const CString& strMask)

Parses a string containing '#', comma, and period characters to determine the format of the number that the user may enter. For example: #,###.# means: (1) allow up to 4 digits before the decimal point, (2) insert commas every 3 digits before the decimal point, (3) use a dot as the decimal point, and (4) allow up to one digit after the decimal point.
解析一个包含'#',逗号和句点字符的字符串,以确定用户可以输入的数字格式。例如:#####是指:(1)允许小数点前多达4位,(2)小数点前的每3个数字插入一个逗号,(3)使用一个点作为小数点, (4)小数点后允许最多一位数。

CString GetMask() const

获取一个字符串,这个字符串包含'#'、逗号和句点字符,它表示了用户可以输入的数值字符串格式。

void SetRange(double dMin, double dMax)

设置允许有效数字值范围。默认情况下,从AMS_MAX_NUMBER到AMS_MIN_NUMBER。

void GetRange(double* pdMin, double* pdMax)const

获取允许的有效数字范围。

bool IsValid() const

Returns true if the number is valid and falls within the allowed range.如果数字是有效的且属于允许范围则返回true,。

bool CheckIfValid(bool 
bShowErrorIfNotValid =true)

如果数字是有效的返回true,如果无效,可选地地显示一个错误信息。

void ModifyFlags(UINT uAdd, UINT uRemove)

允许添加或删除控件的标志。这可能用来设置/清除标志,下面是控件行为的标志:

AddDecimalAfterMaxWholeDigits

Inserts the decimal symbol automatically when the user enters a digit and all the whole numbers have already been entered.
当用户输入一个数字且所有的数字已经输入完成,则自动添加小数点符号。

PadWithZerosAfterDecimalWhenTextChanges

Automatically pads the number with zeros after the decimal point any time the text is changed (using SetWindowText or a key stroke).
只要文本被修改,在小数点后自动填充零数字(使用SetWindowText函数或一个击键)。

PadWithZerosAfterDecimalWhenTextIsSet

任何时间设置文本后,在小数点后自动填充零数字(使用SetWindowText函数)。

OnKillFocus_PadWithZerosBeforeDecimal

Pads the number with zeros before the decimal symbol up to the max allowed (set by SetMaxWholeDigits).
在小数点符号前垫零,一直到允许的最大个数(由SetMaxWholeDigits设置)。

OnKillFocus_PadWithZerosAfterDecimal

在小数点符号后垫零,一直到允许的最大个数(由SetMaxDecimalPlaces设置)。

OnKillFocus_DontPadWithZerosIfEmpty

如果使用了上述两个“垫”标志其一,也使用了本标记,如果值为空,则不填充,。

OnKillFocus_Beep_IfInvalid

如果不是一个有效的数字发出蜂鸣声。

OnKillFocus_Beep_IfEmpty

如果没有值则蜂鸣。

OnKillFocus_Beep

如果值是无效的或尚未输入发出蜂鸣声。

OnKillFocus_SetValid_IfInvalid

如果值不是一个有效的值,改变成有效的。

OnKillFocus_SetValid_IfEmpty

如果控件是空的,填充一个有效的数字。

OnKillFocus_SetValid

如果它是空的或无效的值,设置一个有效的数字。

OnKillFocus_SetFocus_IfInvalid

如果它的值是无效的,焦点设回到控件上。

OnKillFocus_SetFocus_IfEmpty

如果它不包含一个值,焦点设回到控件上。

OnKillFocus_SetFocus

如果它是空的或无效,焦点设回到控件上。

OnKillFocus_ShowMessage_IfInvalid

如果值不是一个有效的值,显示一个错误消息框。

OnKillFocus_ShowMessage_IfEmpty

如果它不包含一个值,显示错误消息框,。

OnKillFocus_ShowMessage

如果它不是有效或为空,显示了一个错误提示框。

CAMSIntegerEdit


这个类只允许输入整数的值。它派生自

 

CAMSCurrencyEdit


这个类用于输入货币值。它从CAMSNumericEdit派生, 但它的前缀以指定的区域设置的货币符号(如'$')来设置。它还使用在本地化环境里指定的字符(如逗号)来分隔千。它设置小数点后的最大位数为两个。


CAMSDateEdit


本类处理的一个格式非常具体的日期:MM / DD / YYYY日/月/年,取决于语言环境。当用户输入数字时,斜线是自动填充。用户只可从从右端把输入的字符删除掉。这确保该值保持适当的格式。作为奖励,根据插入符的位置,用户可以使用向上/向下箭头键递增/递减,月,日,或一年。


成员

描述

void SetDate(int nYear, int nMonth, int nDay)

设置日期值。

void SetDate(const CTime& date)

设置日期值。

void SetDate(const COleDateTime& date)

设置日期值。

void SetDateToToday()

设置日期值为今天的日期。

CTime GetDate() const

获取日期(小时,分钟和秒为零)。

COleDateTime GetOleDate() const

获取日期(小时,分钟和秒为零)。

int GetYear() const

获取年。

int GetMonth() const

获取月

int GetDay() const

获取日

void SetYear(int nYear)

设置年。

void SetMonth(int nMonth)

设置月份

void SetDay(int nDay)

设置天

bool IsValid() const

如果是有效的日期值返回true。

bool CheckIfValid(bool bShowErrorIfNotValid =true)

如果日期是有效的返回true,如果无效可选地显示一个错误信息。

void SetRange(const CTime& dateMin, constCTime& dateMax)

设定有效日期的允许值范围。默认情况下它是01/01/1900到12/31/9999。

void SetRange(const COleDateTime& dateMin,const COleDateTime& dateMax)

设定有效日期的允许值范围。

void GetRange(CTime* pDateMin, CTime* pDateMax)const

获取日期有效范围。

void GetRange(COleDateTime* pDateMin, COleDateTime* pDateMax) const

获取日期有效范围。

void SetSeparator(TCHAR cSep)

设置用来分隔日期的组件字符。默认情况下它是一个斜线('/')。

TCHAR GetSeparator() const

获取用来分隔日期组件字符。

void ShowDayBeforeMonth (bool bDayBeforeMonth =true)

覆盖本地化环境设置的格式,基于月之前或之后的显示日期用的标记来设置。

bool IsDayShownBeforeMonth () const

如果天将前月之前显示(dd/mm/yyyy),返回true。

void ModifyFlags(UINT uAdd, UINT uRemove)

允许添加或删除控件的标志。当控件失去焦点时,可能会使用以下标志的设置/清除来改变行为,:

OnKillFocus_Beep_IfInvalid

如果该值不是一个有效日期发出蜂鸣声。

OnKillFocus_Beep_IfEmpty

如果没有值则蜂鸣。

OnKillFocus_Beep

如果值是无效的或尚未输入则发出蜂鸣声,。

OnKillFocus_SetValid_IfInvalid

如果它不是一个有效日期则改变值。

OnKillFocus_SetValid_IfEmpty

如果是空的,填充一个有效的日期值(如果允许用今天的日期)。

OnKillFocus_SetValid

如果它是空的或无效的值则设定有效日期。

OnKillFocus_SetFocus_IfInvalid

如果它的值是无效的,设置上焦点,

OnKillFocus_SetFocus_IfEmpty

如果它不包含一个值,则设置上焦点。

OnKillFocus_SetFocus

如果它是空的或无效,设置上焦点,。

OnKillFocus_ShowMessage_IfInvalid

如果值不是一个有效的日期显示错误消息框。

OnKillFocus_ShowMessage_IfEmpty

显示错误消息框,如果它不包含一个值。

OnKillFocus_ShowMessage

显示了一个错误,如果它不是有效的空消息框。

CAMSTimeEdit


This class handles times in a very specific format: HH:mm or hh:mm AM, depending on the locale. Seconds are also supported, but not by default. As the user enters the digits, the colons are automatically filled in. The user may only remove characters from the right side of the value entered. This ensures that the value is kept in the proper format. As a bonus, the user may use the up/down arrow keys to increment/decrement the hour, minute, second, or AM/PM, depending on the location of the caret.
这个类以一个非常具体的格式处理时间,依赖于于本地化环境,格式可为:HH:MM或HH:MM AM。秒也支持,但不是默认。在用户输入数字时,冒号自动填写。用户只可从输入值右端来删除字符。这确保值以适当的格式表示。作为奖励,用户可以使用向上/向下箭头键递增/递减小时、分钟、秒或AM / PM,具体对应谁取决于插入符的位置。


成员

描述

void SetTime(int nHour, int nMinute,
 intnSecond = 0)

设定的时间值。

void SetTime(const CTime& date)

使用给定的日期的时间部分设置时间值。

void SetTime(const COleDateTime& date)

使用给定的日期的时间部分设置时间值

void SetTimeToNow()

以当前时间设置时间值。

CTime GetTime() const

获取时间(日期部分为1899年12月30日)。

COleDateTime GetOleTime() const

获取的时间(日期部分为1899年12月30日)。

int GetHour() const

获取小时。

int GetMinute() const

获取分钟。

int GetSecond() const

获取秒。

CString GetAMPM() const

返回控件当前显示的的AM / PM符号或空字符串。

void SetHour(int nYear)

设置小时。

void SetMinute(int nMonth)

设置分钟。

void SetSecond(int nDay)

设置秒。

void SetAMPM(bool bAM)

如果不是24小时格式,设置上午或下午的符号。

bool IsValid(bool bCheckRangeAlso = true) const

如果是有效的时间值,返回true。如果 bCheckRangeAlso为真,时间值要检查,看是不是在由SetRange所设的范围内。

bool CheckIfValid(bool 
bShowErrorIfNotValid =true)

如果时间是有效且在范围内,返回true,否则可选地显示错误消息。

void SetRange(const CTime& dateMin, constCTime& dateMax)

设置有效时间允许值的范围。默认情况下它是00:00:00到23:59:59。
注:当控件拥有焦点,将允许用户输入00:00:00235959秒之间的任何值,不管SetRange会设置什么范围,不会影响这样输入。

void SetRange(const COleDateTime& dateMin,const COleDateTime& dateMax)

设置有效时间允许值的范围。

void GetRange(CTime* pDateMin, CTime* pDateMax)const

获取有效时间允许的范围。

void GetRange(COleDateTime* pDateMin, COleDateTime* pDateMax) const

获取有效时间允许的范围。

void SetSeparator(TCHAR cSep)

设置用于分隔时间字符。默认情况下,它是一个冒号(':')。

void SetSeparator(TCHAR cSep)

获取用来分隔时间组件的字符。

void Show24HourFormat (bool 
bShow24HourFormat =true)

覆盖本地化环境设置的格式,基于显示时间用的标记来设置,小时可为00到23(24小时制)或带有AM/PM的从01到12。

bool IsShowing24HourFormat () const

如果小时将在24小时格式(而不是12小时的AM / PM符号格式)所示,则返回true。

void ShowSeconds (bool bShowSeconds = true)

秒是否将被显示或不显示。

bool IsShowingSeconds () const

如果秒将会显示返回true。

void SetAMPMSymbols(const CString& strAM, constCString& strPM)

覆盖本地化环境设置的格式,设置上午和下午显示的符号,这可能是任何长度,但都必须是相同的长度。

void GetAMPMSymbols(CString* pStrAM, CString* pStrPM) const

获取显示上午和下午的符号到给定的CString指针。

void ModifyFlags(UINT uAdd, UINT uRemove)

允许添加或删除控件的标志。这可能会使用以下设置/清除标志,当它失去焦点,以改变行为:

OnKillFocus_Beep_IfInvalid

如果该值不是一个有效日期,发出蜂鸣声

OnKillFocus_Beep_IfEmpty

如果没有输入值,则发蜂鸣声。

OnKillFocus_Beep

如果值是无效的或尚未输入,发出蜂鸣声。

OnKillFocus_SetValid_IfInvalid

如果它不是一个有效日期则改变值。

OnKillFocus_SetValid_IfEmpty

如果是空的,填充一个有效的时间值(如果允许为当前时间),

OnKillFocus_SetValid

如果它是空的或无效的值,设定有效日期。

OnKillFocus_SetFocus_IfInvalid

如果它的值是无效的,焦点设置回控件上。

OnKillFocus_SetFocus_IfEmpty

如果它不包含一个值,焦点设置回控件上。

OnKillFocus_SetFocus

如果它是空的或无效,焦点设置回控件上。

OnKillFocus_ShowMessage_IfInvalid

如果值不是一个有效的时间,显示错误消息框。

OnKillFocus_ShowMessage_IfEmpty

如果它不包含值,显示错误消息框。

OnKillFocus_ShowMessage

如果无效或为空,显示了一个错误框。

CAMSDateTimeEdit


这个类的结合显示了日期和时间值,由空格分隔的日期和时间。它包含CAMSDateEdit 和CAMSTimeEdit 类的所有功能,加上了一些扩展。此外,这个类可以使用ModifyFlags功能动态改变,来只接受一个日期或时间值。


成员

描述

void SetDateTime(int nHour, 
int nMinute, intnSecond = 0)

设置日期和时间值。

void SetDateTime(const CTime&
date)

用给定的CTime类型 日期和时间值设置。

void SetDateTime(const 
COleDateTime& date)

用给定COleDateTime 类型日期和时间值设置。

void SetToNow()

用当前的日期和时间设置。

CTime GetDateTime() const

以CTime形式获取日期和时间值。

COleDateTime GetOleDateTime()
 const

以CCOleDateTime形式获取日期和时间值。

bool IsValid() const

如果是有效的日期和时间值返回true。

bool CheckIfValid(bool 
bShowErrorIfNotValid =true)

如果日期和时间是有效的则返回true,否则可选地显示错误消息。

void SetRange(const CTime& dateMin, constCTime& dateMax)

设定有效日期的允许值范围内。默认情况下,它01/01/1900 00:00:00到12/31/9999 23:59:59。

void SetRange(const COleDateTime& dateMin,const COleDateTime& dateMax)

设置有效时间值的范围。

void GetRange(CTime* pDateMin, CTime* pDateMax)const

获取有效时间的范围。

void GetRange(COleDateTime* pDateMin, COleDateTime* pDateMax) const

获取有效时间范围。

void SetSeparator(TCHAR cSep,
 bool bDate)

设置用于分隔的日期或时间组件的字符。默认情况下,日期用斜线('/'),的时间用冒号('')。

TCHAR GetSeparator(bool bDate) const

获取用于分隔的日期或时间组件的字符。

void ModifyFlags(UINT uAdd,
UINT uRemove)

允许添加或删除控件的标志。除了CAMSDateEditCAMSTimeEdit类已有的标记,还有如下标志:

DateOnly

改变这个类只允许一个日期值,就像 CAMSDateEdit类。

TimeOnly

改变这个类只允许一个时间值,就像 CAMSTimeEdit类。
注:如果这些标志都被设置,TimeOnly标志将被忽略。

CAMSMaskedEdit
这个类擅长处理固定的数字格式,如电话号码,社会安全号码,邮政编码。


成员

描述

void SetMask(const CString& strMask)

设置输入格式。默认情况下,每个掩码符号“#”代表一个数字。在用户输入数字时,#符号之间的任何其他字符将被自动填写。
额外的字符可以加上来被解释为特殊的掩码符号。请参阅GetSymbolArray。

const CString& GetMask() const

获取用来格式化用户输入的值的掩码。

CString GetNumericText() const

不带任何非数字字符获取控件值。

SymbolArray& GetSymbolArray ()

获取掩码里出现的符号数组的引用。默认情况下,这个数组将包含一个#符号的元素。
使用此功能,添加、编辑或删除符号(见 CAMSEDit :: MaskedBehavior ::符号类 amsEdit.h)。下面是一些例子代码演示如何使用增加额外的符号:


/ / 添加'允许字母符号
m_ctlMasked.GetSymbolArray().Add( ? CAMSMaskedEdit::Symbol('?', _istalpha));

/ / 添加“{”符号允许字母
/ / 字符,然后将它们转换为大写。

m_ctlMasked.GetSymbolArray().Add( ? CAMSMaskedEdit::Symbol('{', _istalpha, ? _totupper));

CAMSMultiMaskedEdit
This class is capable of dynamically taking on the behavior of any of the above classes based on the mask assigned to it. See SetMask below for more details. It contains not only it's own member functions but also those of the Alphanumeric, Numeric, Masked, and DateTime classes above. With such high overhead, I recommend you only use this class for controls which must dynamically change from one behavior to another at run time. The default behavior is Alphanumeric.
这个类是能够根据分配给它的掩码动态地使用上面的类的行为。下面的SetMask说明会有更多的细节。它不仅包含自己的成员函数,而且这些字母数字、数字、掩码和上面的DateTime类。如此高的开销,我建议你在必须运行时动态地改变行为时才用这个类。默认行为是字母数字。


成员

描述

void SetMask(const CString& strMask)

设置要输入值的格式。

  • ##/##/########## =日期和时间(以秒为单位) 
    月的位置和小时格式从本地化环境获取。
  • ##/##/######## =日期和时间(秒) 
    月的位置和小时格式从本地化环境获取。
  • ##/##/#### =日期。
    月的位置从本地化环境获取。
  • ##:####。=时间(秒)
    小时格式的位置从本地化环境获取。
  • ###。=时间(秒)
    小时格式的位置从本地化环境获取。

如果它像数字值,如###或#,###.### (第一个#字符后没有外文),那么它视为数字;否则它被视为掩码(例如,处理 ###-####)。

const CString& GetMask() const

获取用来格式化用户输入值的掩码。

用法

这些类设计于CDialog的派生类里使用,替代通常用类向导创建的CEdit变量。在你的项目需要使用,请按如下步骤处理:

  1. amsEdit.cppamsEdit.h添加到您的项目。
  2. 在你的源文件里包含amsEdit.h。我建议,包含到stdafx.h这样只需要添加一个位置。
  3. 用VS添加对话框内的编辑控件。
  4. 使用类向导“选项卡”成员变量“,绑定你的编辑控制CEdit的变量。
  5. 类向导关闭后,打开对话框的头文件,把需要修改的编辑框的控件类型改变为一个派生CAMSEdit类。
  6. 如果有必要,使用OnInitDialog处理函数,例如调整任何设置,如初始值,范围等,如果你有 CAMSDateEdit的类,你可能希望使用SetRange函数设置它的日期范围。
友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内