fix etcpmon keyboard: move Tab/Enter/Esc from WndProc to message loop pre-translate

This commit is contained in:
Evgeny committed 2026-04-25 19:27:01 +03:00
1 parent 973c00e544
commit bbebc74bdb
1 file changed
+25 -25
+25 -25
View File
@@ -972,31 +972,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
return 0;
}
break;
case WM_KEYDOWN:
if (app) {
switch (wParam) {
case VK_TAB: {
HWND hFocus = GetFocus();
if (hFocus == app->hEditAddr) {
SetFocus(app->hEditPort);
int len = GetWindowTextLengthA(app->hEditPort);
SendMessageA(app->hEditPort, EM_SETSEL, len, len);
} else if (hFocus == app->hEditPort) {
SetFocus(app->hEditAddr);
int len = GetWindowTextLengthA(app->hEditAddr);
SendMessageA(app->hEditAddr, EM_SETSEL, len, len);
}
return 0;
}
case VK_RETURN:
if (!app->isConnected) OnConnect(app);
return 0;
case VK_ESCAPE:
if (app->isConnected) OnDisconnect(app);
return 0;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
@@ -1185,6 +1160,31 @@ int etcpmon_gui_run(struct etcpmon_app* app) {
UpdateWindow(app->hWndMain);
MSG msg;
while (GetMessageA(&msg, NULL, 0, 0)) {
if (msg.message == WM_KEYDOWN && app) {
HWND hFocus = GetFocus();
if (hFocus == app->hEditAddr || hFocus == app->hEditPort) {
if (msg.wParam == VK_TAB) {
if (hFocus == app->hEditAddr) {
SetFocus(app->hEditPort);
int len = GetWindowTextLengthA(app->hEditPort);
SendMessageA(app->hEditPort, EM_SETSEL, len, len);
} else {
SetFocus(app->hEditAddr);
int len = GetWindowTextLengthA(app->hEditAddr);
SendMessageA(app->hEditAddr, EM_SETSEL, len, len);
}
continue;
}
if (msg.wParam == VK_RETURN) {
if (!app->isConnected) OnConnect(app);
continue;
}
if (msg.wParam == VK_ESCAPE) {
if (app->isConnected) OnDisconnect(app);
continue;
}
}
}
TranslateMessage(&msg);
DispatchMessageA(&msg);
}