From 51646002cd6d07c9d2ace22d3f526aeb33135734 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Fri, 9 Jul 2021 13:10:40 -0700 Subject: [PATCH] Fixed windows service install dialog box button placement. --- meshservice/ServiceMain.c | 19 +++++++++++++++++-- microscript/ILibDuktape_Commit.h | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/meshservice/ServiceMain.c b/meshservice/ServiceMain.c index 8bee297..789c8aa 100644 --- a/meshservice/ServiceMain.c +++ b/meshservice/ServiceMain.c @@ -881,6 +881,8 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP { char *fileName = NULL, *meshname = NULL, *meshid = NULL, *serverid = NULL, *serverurl = NULL, *installFlags = NULL, *mshfile = NULL; char *displayName = NULL, *meshServiceName = NULL; + int hiddenButtons = 0; // Flags: 1 if "Connect" is hidden, 2 if "Uninstall" is hidden, 4 is "Install is hidden" + UNREFERENCED_PARAMETER(lParam); switch (message) { @@ -1084,17 +1086,20 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP if (meshid == NULL) { EnableWindow(GetDlgItem(hDlg, IDC_CONNECTBUTTON), FALSE); } if ((installFlagsInt & 3) == 1) { // Temporary Agent Only + hiddenButtons |= 6; // Both install and uninstall buttons are hidden ShowWindow(GetDlgItem(hDlg, IDC_INSTALLBUTTON), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), SW_HIDE); GetWindowPlacement(GetDlgItem(hDlg, IDC_INSTALLBUTTON), &lpwndpl); SetWindowPlacement(GetDlgItem(hDlg, IDC_CONNECTBUTTON), &lpwndpl); } else if ((installFlagsInt & 3) == 2) { // Background Only + hiddenButtons |= 1; // Connect button is hidden hidden ShowWindow(GetDlgItem(hDlg, IDC_CONNECTBUTTON), SW_HIDE); } else if ((installFlagsInt & 3) == 3) { // Uninstall only GetWindowPlacement(GetDlgItem(hDlg, IDC_INSTALLBUTTON), &lpwndpl); SetWindowPlacement(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), &lpwndpl); + hiddenButtons |= 5; // Both install and connect buttons are hidden ShowWindow(GetDlgItem(hDlg, IDC_INSTALLBUTTON), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CONNECTBUTTON), SW_HIDE); } @@ -1104,7 +1109,6 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP EnableWindow(GetDlgItem(hDlg, IDC_CONNECTBUTTON), FALSE); } - // Get the current service running state int r = GetServiceState(meshServiceName != NULL ? meshServiceName : serviceFile); SetWindowTextW(GetDlgItem(hDlg, IDC_INSTALLBUTTON), update_buttontext); @@ -1117,14 +1121,25 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP case 0: case 100: // Not installed SetWindowTextW(GetDlgItem(hDlg, IDC_STATUSTEXT), state_notinstalled); - ShowWindow(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), SW_HIDE); SetWindowTextW(GetDlgItem(hDlg, IDC_INSTALLBUTTON), install_buttontext); + hiddenButtons |= 2; // Uninstall buttons is hidden + ShowWindow(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), SW_HIDE); break; default: // Not running SetWindowTextW(GetDlgItem(hDlg, IDC_STATUSTEXT), state_notrunning); break; } + // Correct the placement of buttons, push them to the left side if some of them are hidden. + if (hiddenButtons == 2) { // Uninstall button is the only one hidden. Place connect button at uninstall position + WINDOWPLACEMENT lpwndpl; + GetWindowPlacement(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), &lpwndpl); + SetWindowPlacement(GetDlgItem(hDlg, IDC_CONNECTBUTTON), &lpwndpl); + } else if (hiddenButtons == 6) { // Only connect button is showing, place it in the install button location + WINDOWPLACEMENT lpwndpl; + GetWindowPlacement(GetDlgItem(hDlg, IDC_INSTALLBUTTON), &lpwndpl); + SetWindowPlacement(GetDlgItem(hDlg, IDC_CONNECTBUTTON), &lpwndpl); + } if (mshfile != NULL) { free(mshfile); } Duktape_SafeDestroyHeap(ctx); diff --git a/microscript/ILibDuktape_Commit.h b/microscript/ILibDuktape_Commit.h index 07ddc15..6de4fb5 100644 --- a/microscript/ILibDuktape_Commit.h +++ b/microscript/ILibDuktape_Commit.h @@ -1,3 +1,3 @@ // This file is auto-generated, any edits may be overwritten -#define SOURCE_COMMIT_DATE "2021-Jul-9 12:34:15-0700" -#define SOURCE_COMMIT_HASH "b9ab7d3ca3f479c27ecceb6a6521a24a6dc6a5ad" +#define SOURCE_COMMIT_DATE "2021-Jul-9 12:40:53-0700" +#define SOURCE_COMMIT_HASH "2a2386b78e4a6ea591d7b192957377d5f2e70d9f"