Question

Is there any way to validate the contents of a CEdit box without subclassing?

I want to check for invalid filename characters in a CEdit box and not allow the user to input it at all (keypress should not be recorded, if pasted in the box, the invalid characters should just not make it to the edit box)..

Is there any easy way to do this?

On a side note, how do I make a variable that is tied to this box? If I add a variable that is not a control one, would this variable always contain what is in the edit control?

Thanks..

Was it helpful?

Solution

Per http://msdn.microsoft.com/en-us/library/f7yhsd2b(VS.80).aspx , "If you want to handle Windows notification messages sent by an edit control to its parent (usually a class derived from CDialog), add a message-map entry and message-handler member function to the parent class for each message." and "ON_EN_UPDATE The edit control is about to display altered text. Sent after the control has formatted the text but before it screens the text so that the window size can be altered, if necessary." -- so, without subclassing CEdit, you can vet and possibly block updates via the windows message-map/message-handler in the parent.

OTHER TIPS

Some time long ago I created this. Granted, this is very dated but ideas still hold:

alt text

Override PreTranslateMessage in your dialog. When the mesage is WM_KEYDOWN and GetFocus() returns the HWND of your edit control, eat the message when you don't like the key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top