From d65e2ab2d401032726dc842f19ab2613a46ee094 Mon Sep 17 00:00:00 2001 From: Lavius Motileng <58791731+laviusmotileng-ms@users.noreply.github.com> Date: Tue, 5 May 2020 14:02:55 -0700 Subject: [PATCH] FIX : [Settings] - Can start multiple settings dialogs (#2421) * Launch new wpf process with same/old ipc names * updated bring window to front * reverted change * removed unused string --- src/runner/settings_window.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index 112cbf8021..06e6f0c1a2 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -350,15 +350,27 @@ LExit: g_settings_process_id = 0; } +#define MAX_TITLE_LENGTH 100 void bring_settings_to_front() { auto callback = [](HWND hwnd, LPARAM data) -> BOOL { DWORD processId; if (GetWindowThreadProcessId(hwnd, &processId) && processId == g_settings_process_id) { - ShowWindow(hwnd, SW_NORMAL); - SetForegroundWindow(hwnd); - return FALSE; + std::wstring windowTitle = L"PowerToys Settings"; + + WCHAR title[MAX_TITLE_LENGTH]; + int len = GetWindowTextW(hwnd, title, MAX_TITLE_LENGTH); + if (len <= 0) + { + return TRUE; + } + if (wcsncmp(title, windowTitle.c_str(), len) == 0) + { + ShowWindow(hwnd, SW_RESTORE); + SetForegroundWindow(hwnd); + return FALSE; + } } return TRUE;