I think this boils down to three basic questions.
1) How do I determine when a user enters a character in a CWNumEdit?
2) How do I suppress the error message that the CWNumEdit displays when the user commits an invalid value?
3) Is it possible to customize the message box that CWNumEdit displays when the user commits an invalid value?
The answer to (1) is that you handle the KeyDown event.
You were right on track with the answers to (2) and (3). You need to handle the Error event. In the Error event you can either cancel the error, thus suppressing the message box, or you can change the text that the message box displays.
You were not able to get your message handler to work because of a known issue with ActiveX control stock error event
s.
>See the KB about this issue for more information.
Fortunately, there is a workaround. Your message handler should look something like the following:
ON_EVENT(CRangeCheckingDlg, IDC_CWNUMEDIT_VALUE, -608 /* Error */, OnErrorCwnumeditValue, VTS_I2 VTS_PBSTR VTS_I4 VTS_BSTR VTS_BSTR VTS_I4 VTS_PBOOL)
To fix the issue, you need to change the first VTS_I4 to VTS_SCODE. So, you should end up with something like the following:
ON_EVENT(CRangeCheckingDlg, IDC_CWNUMEDIT_VALUE, -608 /* Error */, OnErrorCwnumeditValue, VTS_I2 VTS_PBSTR VTS_SCODE VTS_BSTR VTS_BSTR VTS_I4 VTS_PBOOL)
To cancel the event, set the last parameter to TRUE in your error event callback. This would look something like the following:
*CancelDisplay = TRUE;
Alternatively, you can set the Description parameter to a custom value. This would look something like the following:
CString errorMessage("
My custom error message.");
*Description = errorMessage.AllocSysString();
The caller will free the string that you allocate with CString::AllocSysString.