Pass foreground rights to the emperor (#18325)

Forgetti di spaghetti in #18215.

Closes #18324

## Validation Steps Performed

* Launch through the start menu
* Explicitly minimize
* Then...
  * Launch through the start menu again 
  * Launch via wtd.exe in Win+R 
  * Launch via wtd.exe in another Terminal 
  * Launch via handoff 
This commit is contained in:
Leonard Hecker 2024-12-13 09:13:03 -08:00 committed by GitHub
parent 19460f98e0
commit 50060452ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -170,6 +170,14 @@ static wil::unique_mutex acquireMutexOrAttemptHandoff(const wchar_t* className,
.cbData = gsl::narrow<DWORD>(payload.size()),
.lpData = payload.data(),
};
// Allow the existing instance to gain foreground rights.
DWORD processId = 0;
if (GetWindowThreadProcessId(hwnd, &processId) && processId)
{
AllowSetForegroundWindow(processId);
}
if (SendMessageTimeoutW(hwnd, WM_COPYDATA, 0, reinterpret_cast<LPARAM>(&cds), SMTO_ABORTIFHUNG | SMTO_ERRORONEXIT, 5000, nullptr))
{
return {};