Pointer disappears when typing into edit box

Hello,

I've created a simple window with a button and an edit box.

If the pointer is inside the window, it disappears if I start typing into the edit box and it only reappears when I click or move the pointer outside the window.

I'd like to know why is this happening, if it is normal and how can I prevent it?

Also, the issue doesn't occur if I disable the "Hide pointer when typing" option from Control Panel.

The pointer only disappears when I type into my window's edit box, it doesn't happen with any other apps like chrome, office, notepad or VS...

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <Windows.h>

WNDCLASSEX wcex;
HWND hwndButton, hwndEdit;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case 666:
			switch (HIWORD(wParam)) {
			case BN_CLICKED:
				wchar_t buffer[1024];
				SendMessage(hwndEdit, WM_GETTEXT, sizeof(buffer) / sizeof(buffer[0]),
					reinterpret_cast<LPARAM>(buffer));
				MessageBox(nullptr, (LPWSTR)buffer, L"Information", MB_ICONINFORMATION | MB_OK);
				break;
			}
			break;
		}
		break;
	case WM_CREATE:
		hwndButton = CreateWindow(L"BUTTON", L"Click me!", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
			10, 10, 100, 35, hwnd, (HMENU)666, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), nullptr);
		hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"type here...",
			WS_VISIBLE | WS_CHILD | ES_LEFT,
			10, 100, 150, 25, hwnd, (HMENU)777, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
			nullptr);		
		break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	const wchar_t* wndClassName = L"MyWindowClass";

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = 0;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
	wcex.hCursor = LoadCursor(hInstance, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszMenuName = nullptr;
	wcex.lpszClassName = wndClassName;
	wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);

	if (!RegisterClassEx(&wcex)) {
		MessageBox(nullptr, L"Window registration failed!", L"Error", MB_ICONERROR | MB_OK);
		return 1;
	}

	HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, wndClassName, L"Title", WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, nullptr, nullptr, hInstance, nullptr);

	if (hwnd == nullptr) {
		MessageBox(nullptr, L"Window creation failed!", L"Error", MB_ICONERROR | MB_OK);
		return 1;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	MSG msg;
	while (GetMessage(&msg, nullptr, 0, 0) > 0) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

Last edited on
Topic archived. No new replies allowed.