[try Beta version]
Not logged in

 
 
How to stop edit control from beeping?

Dec 8, 2016 at 2:47am
I have an edit control and a send button. I have used the following code to subclass the edit control and to capture the press of the "Enter" key:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
WNDPROC OldEditProc;

LRESULT CALLBACK SubEditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
	switch (Msg) {
	case WM_KEYDOWN:
		switch (LOWORD(wParam)) {
		case VK_RETURN:
			//hMainWnd is a handle to the main window
			SendMessage(hMainWnd, WM_COMMAND, (WPARAM)IDC_SEND_MESSAGE_BUTTON, NULL);
			return 0;
		default:;
		}
	default:
		return CallWindowProc(OldEditProc, hWnd, Msg, wParam, lParam);
	}
}

HWND hMsgEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 10, 223, 580, 25, hWnd, (HMENU)IDC_MESSAGE_EDIT_EDIT, hInst, NULL);
OldEditProc = (WNDPROC)SetWindowLongPtr(hMsgEdit, GWLP_WNDPROC, (LONG_PTR)SubEditProc);

My edit control is only single lined, so if you press enter it will beep. Although I returned immediately after I sent the message to the main window, there is still that annoying beep when I press enter in the edit control. How do I fix this?
Dec 8, 2016 at 12:16pm
It seems to work when you handle WM_CHAR instead of WM_KEYDOWN.
Dec 8, 2016 at 10:50pm
Thanks Thomas! That worked for me.
Dec 19, 2016 at 4:35pm
These beeps are coming from the CEdit implementation (in common control dll).
When you exceed the text limit or enter invalid character (alpha for numeric control), it calls MessageBeep().
You could derive your own class from CEdit and implement WM_CHAR handler which will filter invalid characters and will NOT pass them to the base class.
Topic archived. No new replies allowed.