c++validationwinapierror-handlingeditcontrol

Recommend solution for visually indicating invalid input in singleline edit control


I have edit controls in my dialog box. Some of them are numeric, some of them accept floats and some of them are textual.

I am validating edit controls with integer and float input.

I have implemented validation mechanism in response to EN_CHANGE message. I am using MessageBeep(MB_ICONERROR); to indicate invalid input.

I would also like to visually indicate error but do not know how to do it.

Since I have multiple edit controls (15) the best option seems to change the brush in response to WM_CTLCOLOREDIT but I fear this solution will introduce too many new variables. Another option seems to be tooltip, but if more than one edit control has invalid input this might look visually unappealing. That is why I am asking for help here, so I can get advice from experienced and better developers than myself.

What is the best solution for my case, to visually indicate error when user makes one or multiple invalid inputs?


Solution

  • "..but I fear this solution will introduce too many new variables"

    There is room in the memory for thousands of variables. If you need to remember the state for each of 15 edit controls then you need 15 state variables.