Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CWNumEdit error handeling

I'm having a problem with a CWNumEdit box on my user interface. When I input a character, an error message box will appear with the caption "cwui" with the message "Type Mismatch" which also includes a OK button. I have two questions:

1. What do I need to do so that the message box does not appear if a character is entered? Also, how can I determine if a character was entered? I don't need to know what character it is, I just want to know when a character was entered so I can display an error message in another edit box (indicator)?

2. If I can't get rid of the message box, what do I need to do so that I can display my own message box instead of the default one? I've tried to create a function trough the Message Maps window for the
message "Error", but that doesn't seem to work.

Thanks.
0 Kudos
Message 1 of 4
(3,391 Views)
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.
Message 2 of 4
(3,391 Views)
Wonderful! Thanks a lot for your help. Both of your suggestions work as you mentioned. I was beating my self to death over this. Thanks again.
0 Kudos
Message 3 of 4
(3,391 Views)
I understand. I've already submitted a bug report to ensure that we document this limitation in the event help in a future version of Measurement Studio.
0 Kudos
Message 4 of 4
(3,391 Views)