I am writing in C WinAPI a 'Go To Line' dialog of the notepad. I created a number only edit control. But I can still paste words into the edit control! The dialog in the windows notepad does stop this kind of pasting. So how can I do the same thing as it in the notepad?
Asked
Active
Viewed 519 times
2 Answers
2
Subclass the edit control, and when WM_PASTE is received:
OpenClipboard
GetClipboardData
GlobalLock
Now use the returned pointer from GlobalLock to check for non numeric characters. If a non number is found, inform user then:
GlobalUnlock
CloseClipboard
and return 0 from the callback to prevent pasting the data into the edit control.
If it is all numbers, then GlobalUnlock
and CLoseClipboard
and pass message on with CallWindowProc
to allow paste.

Gunner
- 5,780
- 2
- 25
- 40
-
That *IS* the way to do it, using the Windows API. – Gunner Nov 19 '12 at 00:45
0
The documentation for ES_NUMBER (which is what I presume you're using) says:
Allows only digits to be entered into the edit control. Note that, even with this set, it is still possible to paste non-digits into the edit control.
To prevent pasting non-digits, you'll need to scan through the data in the clipboard and prevent pasting if it contains a non-digit.

Jerry Coffin
- 476,176
- 80
- 629
- 1,111