Skip to content

Commit

Permalink
C4Application: Remove Win32 window focus hack
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Fulgen301 committed Aug 8, 2023
1 parent 8919c62 commit 123d311
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 27 deletions.
24 changes: 0 additions & 24 deletions src/C4Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/C4Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
2 changes: 0 additions & 2 deletions src/C4StartupMainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 123d311

Please sign in to comment.