How do I filter data pasted into a CEdit control

I am using a CEdit in a dialog to allow the user to enter data as either Binary (using chars 0 & 1) or Hex ( using chars 0-9 & A-F); It is very similar to the binary editor found in RegEdt32.

I need a mechanism to prevent illegal characters from being pasted from the clipboard.  

The mechanism must not rely on parsing the entire CEdit buffer on each update as there could be a large amount of data present resulting in a poor response time.

The ideal solution would intercept the paste event, examine the paste buffer and NOT perform the paste operation if invalid characters are found.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tommy HuiEngineerCommented:
You can trap the event. You need to derive a class from CEdit. Once you have done that, you can use the Wizard to catch the WM_PASTE event. You should probably also use an accelerator for the dialog to catch the Ctrl-V keys. Once you have the event, you can use OpenClipboard() to inspect the clipboard and change the text before continuing.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paulgriffithsAuthor Commented:
That sorted it!

I had originally wizzed a OnEditPaste() handler for ID_EDIT_PASTE in my CEdit derived class but it never got called.

On your advice I have wizzed a override for CEdit::WindowProc() in my derived class and trapped the WM_PASTE message and it works a treat!

Many Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.