0

I have subclassed CEdit clas (CMyEdit) and I am validating continuously user input througth ON_CHAR message. ON_CHAR procedure sets CMyEdit.isOK member variable to true or false. Is there any way how to deny exit from Edit Box, when the value is not rigth (.isOk = false)? I want not allow user to for example go to other edit box or to other dialog.

Thanks.

Michal Hadraba
  • 347
  • 1
  • 11
  • 3
    As a UI design this approach has been comprehensively discredited. Highlight that the edit is invalid elsewhere on the form and don't permit any actions, like apply or OK to happen until it is valid. – David Heffernan Jan 13 '22 at 20:19
  • Besides, `WM_CHAR` is the wrong message to track changes. The `EN_CHANGE` notification is specifically intended for this. – IInspectable Jan 13 '22 at 20:39
  • Yoy both are rigth, when the standard CEdit it is. I use combination of above validation. Eg. for float number, I have ON_CHAR checking and background color changing if whole input is OK. Because "+." is acceptabe input, but don't valid result. But I have CEdit as a part of CTreeControl. And what to do with no-valid input, when the user click to other CTree and this event cause changing of the contens of the Tree and closing of active CEdit..... I have two possibilities - ignore valid input but prvent to do this action - prevent to exit CEdit. – Michal Hadraba Jan 14 '22 at 06:50
  • 1
    Realistically, you only have one option: Ignore invalid input. This is typically done by handling the [`TVN_ENDLABELEDIT`](https://learn.microsoft.com/en-us/windows/win32/controls/tvn-endlabeledit) notification. – IInspectable Jan 14 '22 at 07:09

0 Answers0