From 67653639de3b761afd15510844d3dac89a1aeab8 Mon Sep 17 00:00:00 2001 From: Leonardo Bernardes <58712628+redddcyclone@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:52:47 -0300 Subject: [PATCH] Add Tab and Esc key handling to main window and fix controls order --- CHANGES | 3 +++ GLPI-AgentMonitor.cpp | 15 +++++++++++---- GLPI-AgentMonitor.rc | 6 +++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 2926458..794f2a1 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Future release * Settings dialog added Currently, the only setting available is "New ticket page URL", for changing the URL used to create new tickets (i.e. when using Form Creator) + +* Main window now handles Tab and Esc key pressing + This is a helpful feature for keyboard-only navigation 1.2.3 diff --git a/GLPI-AgentMonitor.cpp b/GLPI-AgentMonitor.cpp index d53bd96..1888ec9 100644 --- a/GLPI-AgentMonitor.cpp +++ b/GLPI-AgentMonitor.cpp @@ -301,7 +301,9 @@ VOID CALLBACK UpdateServiceStatus(HWND hWnd, UINT message, UINT idTimer, DWORD d colorSvcStatus = RGB(255, 0, 0); SetDlgItemText(hWnd, IDC_SERVICESTATUS, szBuffer); SetDlgItemText(hWnd, IDC_BTN_STARTSTOPSVC, szBtnString); - EnableWindow(GetDlgItem(hWnd, IDC_BTN_STARTSTOPSVC), FALSE); + HWND hWndSvcButton = GetDlgItem(hWnd, IDC_BTN_STARTSTOPSVC); + EnableWindow(hWndSvcButton, FALSE); + SetFocus(hWndSvcButton); } LoadIconMetric(hInst, MAKEINTRESOURCE(IDI_GLPIERR), LIM_LARGE, &nid.hIcon); @@ -369,7 +371,9 @@ VOID CALLBACK UpdateServiceStatus(HWND hWnd, UINT message, UINT idTimer, DWORD d LoadString(hInst, (svcStatus.dwCurrentState == SERVICE_STOPPED ? IDS_ERR_NOTRUNNING : IDS_WAIT), szBuffer, dwBufferLen); SetDlgItemText(hWnd, IDC_AGENTSTATUS, szBuffer); - EnableWindow(GetDlgItem(hWnd, IDC_BTN_STARTSTOPSVC), bEnableButton); + HWND hWndSvcButton = GetDlgItem(hWnd, IDC_BTN_STARTSTOPSVC); + EnableWindow(hWndSvcButton, bEnableButton); + SetFocus(hWndSvcButton); // Taskbar icon routine if (svcStatus.dwCurrentState != SERVICE_RUNNING) @@ -841,8 +845,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance MSG msg; while (GetMessage(&msg, nullptr, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); + if (!IsDialogMessage(hWnd, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } CloseServiceHandle(hSc); @@ -976,6 +982,7 @@ LRESULT CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ForceInventory(hWnd); return TRUE; // Close + case IDCANCEL: // This handles ESC key pressing via IsDialogMessage case IDC_BTN_CLOSE: EndDialog(hWnd, NULL); return TRUE; diff --git a/GLPI-AgentMonitor.rc b/GLPI-AgentMonitor.rc index 39655c3..615c179 100644 --- a/GLPI-AgentMonitor.rc +++ b/GLPI-AgentMonitor.rc @@ -483,8 +483,6 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTI CAPTION "IDS_APP_TITLE" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - DEFPUSHBUTTON "IDS_FORCEINV",IDC_BTN_FORCE,44,248,72,16 - PUSHBUTTON "IDS_CLOSE",IDC_BTN_CLOSE,88,296,72,16 CTEXT "IDS_APP_TITLE",IDC_STATIC_TITLE,17,76,215,8 CTEXT "vX.XX",IDC_VERSION,17,87,215,8 GROUPBOX "IDS_STATIC_INFO",IDC_GBMAIN,7,100,235,103 @@ -497,10 +495,12 @@ BEGIN RTEXT "IDS_LOADING",IDC_SERVICESTATUS,104,139,124,8 RTEXT "IDS_LOADING",IDC_STARTTYPE,100,157,128,8 CONTROL "",IDC_PCLOGO,"Static",SS_BITMAP,94,9,15,13 + DEFPUSHBUTTON "IDS_STARTSVC",IDC_BTN_STARTSTOPSVC,82,177,86,16 + PUSHBUTTON "IDS_FORCEINV",IDC_BTN_FORCE,44,248,72,16 PUSHBUTTON "IDS_NEWTICKET",IDC_BTN_NEWTICKET,132,248,72,16 PUSHBUTTON "IDS_VIEWLOGS",IDC_BTN_VIEWLOGS,44,272,72,16 - PUSHBUTTON "IDS_STARTSVC",IDC_BTN_STARTSTOPSVC,82,177,86,16 PUSHBUTTON "IDS_BTN_SETTINGS",IDC_BTN_SETTINGS,132,272,72,16 + PUSHBUTTON "IDS_CLOSE",IDC_BTN_CLOSE,88,296,72,16 END IDD_DLG_SETTINGS DIALOGEX 0, 0, 357, 69