|
|
Edit control (pattern matching)
EDIT control, which filters the user's input.
The control uses a mask to make sure that the user enters data in the required format. A pattern-matching algorithm enforces the mask.
In addition, the control supports a number of different styles to
provide visual cues for error indication and handling.
Pattern MatchingThe pattern-matching algorithm supports the following tokens:* = match all ? = match single [abc] = match set [a-z] = match range [^a-z] = exclude range \x = escapeThough using Regular Expressions would have provided greater flexibility, this pattern algorithm is quite good for simple masks.
The default pattern is a Visual cuesThe control offers a range of visual (and audio) cues to signal problems in the input. One or more cues can be enabled.Error BeepWhen the user attempts to enter a text, which doesn't comply with the pattern mask, the control will play the standard beep sound and refuse to change the text.Red marksThe control displays the offending part of the text in red color to show the user where the mistake was made.Red stripesThe control shows red wavy underlines to indicate input errors in the text. The underlines start at the offending character position.This is the effect known from Microsoft Word's spell checker. It works only if you allow a few additional pixels to the EDIT control's height.
Tool TipIn the event of an error, a tooltip can be shown above the edit control and in a distinctive red color. The tool tip text must be supplied by the owner window by supporting theTTN_GETDISPINFO tool tip notification.
The owner can use methods such as GetParseState() and
GetWindowText() to deduce what is wrong with the
input to provide different tooltip texts in different situations.
The color of the tip background and text can be changed. Success coloringYou can set a different the text color when the input text matches the pattern. This way the user will know when the input text is accepted.How to use itTo use this WTL control, place an Edit control on your dialog.Add a member variable to your dialog implementation file...
In the OnInitDialog() event handler, add the following line:
Add the following reflection macro to your main message map:
Use the following initialisation code to set the control to display wavy underlines to indicate errors in the input text. The pattern allows text like 1G0b and 2G22.
Source Code DependenciesMicrosoft Visual C++ 6.0Microsoft WTL 3.0 Library See AlsoA more simple filtering Edit controlDownload Files
Written by Bjarke Viksoe. Article submitted 6/7/2001. To the top
|
|||