Hit Enter in Textfield

Sep 12, 2018 at 1:10pm
Hello, I've created a window via CreateWindowEx
Problem is, I can't detect hitting enter in a txtfield
Enter can only be detected in the window form, but not inside txtfield..
Thanks in advance.
Sep 12, 2018 at 2:37pm
Hello,

You could install an eventFilter on whatever your using for your txtfield.

Regards
Sep 12, 2018 at 2:57pm
1
2
3
4
5
Case WM_CREATE:
txtfield = CreateWindow(L"EDIT", L"",
			WS_VISIBLE | WS_CHILD | WS_BORDER,
			8, 525, 380, 25,
			hwnd, (HMENU)3, NULL, NULL);


how can I check "If user hit enter" inside the txtfield? an example would be highly appreciated,
Thanks in advance.
Sep 12, 2018 at 3:16pm
Have a look at WM_CHAR, if key == VK_RETURN than check if the txtfield is the active window with GetActiveWindow
Sep 12, 2018 at 3:24pm
if (GetActiveWindow == txtfield)
or how do i properly type the statement?
Sep 12, 2018 at 3:35pm
GetActiveWindow returns a handle to a window, so you can compare it with the txtfield
GetActiveWindow() == txtfield
Sep 12, 2018 at 3:38pm
1
2
3
4
5
6
7
8
switch (message)
	{
	case WM_CHAR://Process this message to avoid message beeps.
		if ((wParam == VK_RETURN))
		{
			if (GetActiveWindow() == txtfield)
				cout << "Enter pressed" << endl;
		}


Still no luck in seeing the print (I use console for printing to test)
Sep 12, 2018 at 3:52pm
Maybe txtfield isn't the active window at the moment.
Try GetForegroundWindow instead
Sep 12, 2018 at 4:33pm
Thank you!!
Topic archived. No new replies allowed.