Disable input focus on button, retain visual "clicked" apperance.

Hello, I'm just learning and here is the code with simple window and a button.

I don't like when clicking on a button how the button has dashed line showing the input focus, to remove that dashed line I process WM_KILLFOCUS on line 56 message.

That works but the problem is that a button when clicked does not get clicked visually. how should I say, it appears stoned. doesn't respond visually when clicked.

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
#include <Windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR szCmdLine, int iCmdShow)
{
	static WCHAR szAppName[] = L"Window";

	WNDCLASS wc;

	wc.lpfnWndProc = WndProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.lpszClassName = szAppName;
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

	RegisterClass(&wc);

	HWND hwnd = CreateWindow(szAppName, L"MainWindow", WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 700, 400,
		NULL, NULL, hInstance, NULL);

	ShowWindow(hwnd, iCmdShow);
	UpdateWindow(hwnd);

	MSG msg = {};
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HWND button;

	switch (message)
	{
	case WM_CREATE:
	{
		button = CreateWindow(L"button", L"Close",
			WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
			10, 10, 100, 50, hwnd, (HMENU)1,
			((LPCREATESTRUCT)lParam)->hInstance, NULL);
		return 0;
	}

	case WM_KILLFOCUS:
		if (button = (HWND)wParam)
			SetFocus(hwnd);
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	}
}
Last edited on
Look at handling the WM_CHANGEUISTATE message you might be able to block the calls to change the active visual elements...
Registered users can post here. Sign in or register to post.