YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
View in English
View in Japanese
View in
참고
View in Français
View in Italiano
View in 中文(繁體)
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


VC++ Example CFilterEdit Regular Expression : Use Regular Expression to Filter Your Input, Boost C++ Library

 
 By Ben
The definitive approach to filtering input text. Includes configurable error display.
Screenshot - FilterEdit.png

Introduction

 

Ever since computers were invented, data validation has been an important concern. When it comes to a user interface, the fastest way to validate data is whilst it is being input. Strange, then, that there is no standard Windows Edit Regular Expression  control that tackles this problem for any kind of data.

This validating Edit Regular Expression  control aims to provide the ultimate Framework for data validation, no matter how complex the data you are attempting to input is.

Design Decisions

  • Validation must be clean and reliable
  • The control should be usable exactly like CEdit Regular Expression  
  • Only a handful of visual effects will be included as standard
  • 'WM_KILLFOCUS is the wrong time to do field validation'
  • Auto-formatting should be easy to add from a derived class
  • FilterEdit Regular Expression  must stay as simple as possible and not get too bloated!

Intercepted Windows Messages

The following Windows messages are trapped for validation purposes...

  • EM_REPLACESEL
  • WM_CLEAR
  • WM_CHAR
  • WM_CUT
  • WM_KEYDOWN
  • WM_KEYUP
  • WM_KILLFOCUS
  • WM_PASTE
  • WM_SETFOCUS
  • WM_SETTEXT

... and these are trapped to perform the visual effects:

  • WM_CTLCOLOR
  • WM_PAINT

Windows Message Overrides for Validation

CBaseEdit Regular Expression ::OnChar

WM_CHAR is the Windows message that every validating Edit Regular Expression  control ever written for Windows must have trapped. This is where a single character can be checked to see if the control will accept it or not.

CBaseEdit Regular Expression ::OnKeyDown

WM_KEYDOWN is where the Delete key, Ctrl-X, Ctrl-C and Ctrl-V are trapped.

CBaseEdit Regular Expression ::OnKillFocus

Again, WM_KILLFOCUS is a very popular message to trap. However, rather than trying to set the focus back to the control in the event that the input is incomplete, we just flag the error and allow the focus to switch normally.

CBaseEdit Regular Expression ::OnSetFocus

WM_SETFOCUS is trapped simply so that we can set any colours we need to and display a tooltip if required.

CBaseEdit Regular Expression ::WindowProc

This is where the rest of the Windows messages we are interested in are processed.

How to Derive Your Own Custom Control

Here are the four obvious things you might want to do:

  • Override SemanticCheck

    See the CUIntRangeEdit Regular Expression  example to see how this works.

  • Trap WM_CHAR yourself

    By trapping characters yourself, you can automatically format input and perform semantic validation as the user types. Refer to the CDateTimeEdit Regular Expression  example to see how this works.

  • Trap WM_KILLFOCUS yourself

    You may want to perform extra formatting when the user leaves the control. Again, see the CDateTimeEdit Regular Expression  example. Don't forget to call CBaseEdit Regular Expression ::OnKillFocus if you do this!

  • Override SyntaxCheck

    This is if you want to pre-process the string before running the syntax checking. See CDateTimeEdit Regular Expression  for an example.

Example Controls Included in the ZIP

  • CCurrencyEdit
  • CDateTimeEdit
  • CFloatEdit
  • CIntEdit
  • CUIntEdit
  • CUIntRangeEdit
  • CSpin

Tooltip Support

You might want to explain the data format for your controls at runtime. For this reason, Balloon Help support is included. To include this support, you must call CreateToolTip:

BOOL CEdit TestDlg::OnInitDialog()
{
    CDialog::OnInitDialog ();
    ...
    m_DateEdit .CreateToolTip (this, _T("Tooltip text here"));
    ...
}

The C++ Standard Regular Expression Library

The boost::regex library has been accepted into the C++ Standard Library. Due to its partial match support, the library is also ideal for this control. Get the Boost library here.

 

 

 

 

Copyright ?1998-2024 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net