Masked Edit Control (3)
Posted
by Jeff Knight
on October 28th, 1998
We had been using the MSMask.ocx control in our MFC application for almost a year. Recently a 200K memory leak was traced to the setText method (200K each time it was called), so we downloaded another masked edit class from the web, but it flickered intensely and the code was kind of icky. Anyway, I decided to write my own. Turns out it works better than I could have hoped. It's easy to use and the source code very simple allowing anyone to extend it as necessary.
In ::OnInitDialog()
m_maskEdit.SubclassDlgItem(IDC_EDIT_MASK, this);
// Initialize the control to "State: KS, Zip: 66202-1234"
m_maskEdit.setMask("State: ??, Zip: #####-####");
m_maskEdit.setText("KS662021234");
In ::OnOk()
// getText returns "KS66202123" CString strTemp = m_maskEdit.getText(); // GetWindowText yields "State: KS, Zip: 66202-1234" m_maskEdit.GetWindowText(strTemp);

Comments
Kleiner Bug ?
Posted by mobo2000 on 01/26/2005 03:39amI have tested a simple example "##,##". When I insert a ',' as the 4. character then this character will be discard, but the insertion point of edit control goes to next character. I think, this ist not a good way. I havn't test other examples. Could be this behaviour is the default for your edit control.
Replymaskeditctrl
Posted by Legacy on 08/30/2003 12:00amOriginally posted by: subramanian.v
sir
Replyi dont know from which class u derived the setMask() methods.
plz mail me.
i m inurgent.
http://www.ucancode.net
Posted by Legacy on 07/11/2003 12:00amOriginally posted by: XD++ MFC Class Library with Source Code!
Cool!
ReplyExEditors Library
Posted by Legacy on 03/19/2002 12:00amOriginally posted by: Mike Philips
ReplyExcellent Work guys
Posted by Legacy on 01/25/2002 12:00amOriginally posted by: fleming george k
Just what i was looking for ..you guys rock
Replyhow to use in a FormView
Posted by Legacy on 05/08/2001 12:00amOriginally posted by: Julia
Hi,
I find it is very useful for me. However, I failed in useing it in a FormView. How to do it?
It would be very much appreciated if anyone could give me instruction on this.
Julia
ReplyPasting Problem?
Posted by Legacy on 11/04/1999 12:00amOriginally posted by: Simon Beck
After trying the demo I noticed that if you paste text into the edit control, only the last character of pasted text is actually displayed.
ReplyDeleting text
Posted by Legacy on 07/20/1999 12:00amOriginally posted by: Johnny D
When the selection is hilighted and the user hit the delete key, the whole thing should be deleted.
ReplyRE: Minor changes....
Posted by Legacy on 05/18/1999 12:00amOriginally posted by: Catalin A. Culiniac
ReplyMinor changes needed!
Posted by Legacy on 11/20/1998 12:00amOriginally posted by: Victor Boctor
After trying the demo application that you included, I wanted to share wth you my comments:
1. If the user clicks a key which is not compatible with the current character of the mask, the cursor is moved to the next cell. I believe the cursor should not be moved in this case. I would recommend also that a virtual function should be added with to handle such invalid keys.
2. In the example you have the first token is a constant, thus when the user clicks a key the cursor moves to the first editable character and then the second key is written there! I believe the first key should be written.
Thanks.
Reply