From 123d31112f7979f119275dfcc76b6a8ef56f37f9 Mon Sep 17 00:00:00 2001 From: George Tokmaji Date: Tue, 8 Aug 2023 21:45:29 +0200 Subject: [PATCH] C4Application: Remove Win32 window focus hack It is not a good idea and can let Clonk hang if the current foreground windodw is not processing messages. See https://devblogs.microsoft.com/oldnewthing/20130619-00/?p=4043. --- src/C4Application.cpp | 24 ------------------------ src/C4Application.h | 1 - src/C4StartupMainDlg.cpp | 2 -- 3 files changed, 27 deletions(-) diff --git a/src/C4Application.cpp b/src/C4Application.cpp index 44a45d1cb..2abe3ad58 100644 --- a/src/C4Application.cpp +++ b/src/C4Application.cpp @@ -628,30 +628,6 @@ void C4Application::OnCommand(const char *szCmd) } } -void C4Application::Activate() -{ -#ifdef _WIN32 - // Activate the application to regain focus if it has been lost during loading. - // As this is officially not possible any more in new versions of Windows - // (BringWindowTopTop alone won't have any effect if the calling process is - // not in the foreground itself), we are using an ugly OS hack. - DWORD nForeThread = GetWindowThreadProcessId(GetForegroundWindow(), 0); - DWORD nAppThread = GetCurrentThreadId(); - if (nForeThread != nAppThread) - { - AttachThreadInput(nForeThread, nAppThread, TRUE); - BringWindowToTop(FullScreen.hWindow); - ShowWindow(FullScreen.hWindow, SW_SHOW); - AttachThreadInput(nForeThread, nAppThread, FALSE); - } - else - { - BringWindowToTop(FullScreen.hWindow); - ShowWindow(FullScreen.hWindow, SW_SHOW); - } -#endif -} - void C4Application::SetNextMission(const char *szMissionFilename) { // set next mission if any is desired diff --git a/src/C4Application.h b/src/C4Application.h index a9d2272d6..21dff28b0 100644 --- a/src/C4Application.h +++ b/src/C4Application.h @@ -139,7 +139,6 @@ class C4Application : public CStdApp public: virtual void Quit() override; void QuitGame(); // quit game only, but restart application if in fullscreen startup menu mode - void Activate(); // activate app to gain full focus in OS void SetNextMission(const char *szMissionFilename); }; diff --git a/src/C4StartupMainDlg.cpp b/src/C4StartupMainDlg.cpp index dcd2a50ea..b56b7d4c1 100644 --- a/src/C4StartupMainDlg.cpp +++ b/src/C4StartupMainDlg.cpp @@ -304,8 +304,6 @@ void C4StartupMainDlg::OnShown() // First show if (fFirstShown) { - // Activate the application (trying to prevent flickering half-focus in win32...) - Application.Activate(); // Set the focus to the start button (we might still not have the focus after the update-check sometimes... :/) SetFocus(pStartButton, false); }