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?

[Webinar] Streamline your web hosting managementRegister Today

Tommy HuiConnect With a Mentor EngineerCommented:
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.
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
All Courses

From novice to tech pro — start learning today.