1
votes

I used the following code and it worked fine, allowed the user to only enter in numbers. I wanted to increase the functionality by using RichEdit so I added that.

I went from using:

wchar_t sampletext[] = L"foobar";  
HWND inputText = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", sampletext,
    ES_NUMBER | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_MULTILINE,
    10, 10, 500, 75, hWnd, NULL, *hInst, NULL);

to:

LoadLibrary(L"riched32.dll");  

wchar_t sampletext[] = L"foobar";  
HWND inputText = CreateWindowEx(WS_EX_CLIENTEDGE, L"RichEdit", sampletext,
    ES_NUMBER | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_MULTILINE,
    10, 10, 500, 75, hWnd, NULL, *hInst, NULL);

Changing it allowed me to use CTRL+Z and CTRL+A and all but now for some reason I could enter characters that weren't numbers.

How do I fix this so Rich Edit only accepts number in this text field? or
Alternatively, how would I create my own custom filter that would only accept numbers into the text field?

EDIT:
Here's an image of me typing
enter image description here

1
"RichEdit" is a different control class, and has its own styles. - Ben Voigt

1 Answers

4
votes

The "RichEdit" control class has its own set of styles.

But ES_NUMBER is one of them, according to MSDN. However, note the comment by ElmueSoft.

To filter input to only digits without help from the control, you can subclass it. You'd need to handle quite a few messages though. WM_CHAR is the most obvious, but WM_PASTE and WM_SETTEXT can have non-numeric text passed in.

Good information on subclassing: