Saturday, September 25, 2004

You wouldn't think it'd be so bloody hard

to write a proper masked edit control. In principle you intercept the stream of characters being typed at the keyboard, apply your filter criteria to them, discard the ones that your mask disallows and let the others through. And in fact, it really is that simple - if all you do is watch what the user types. Override the WM_CHAR message and filter away.

But that ain't enough. You also have to be careful that your user can't paste data into the edit control that violates your mask criteria. And that's much more difficult to prevent. I'm experimenting with a mixture of WM_CHAR filtering as aforesaid, plus WM_PASTE filtering where I pick the data off the clipboard, examine each character and post a WM_CHAR message to myself for each valid character. Of course I know this is going to bite me in the bum the first time someone tries to use the control on a non-US Windows system but I'll worry about that once I go home.

No comments: