From 4ba4ca7fee09d4af2d44bca66fbf33565f0345f2 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 9 Jun 2012 23:24:59 -0400 Subject: [PATCH] Fullscreen clients no longer hide message boxes The old solution may have worked at one point in time, but it was kind of suspect in that it would (theoretically) hide the game window forever. The new solution will only hide the game window while the message box is alive. As a bonus, the part where we hide the full screen window now works. --- Sources/Plasma/CoreLib/HeadSpin.cpp | 17 --------------- Sources/Plasma/CoreLib/hsUtils.cpp | 33 +++++++++++++++++++++++------ Sources/Plasma/CoreLib/hsUtils.h | 1 - 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index c9a50e54..356109c4 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -175,23 +175,6 @@ void DebugMsg(const char fmt[], ...) } } -void ErrorMinimizeAppWindow () -{ -#ifdef HS_BUILD_FOR_WIN32 - // If the application's topmost window is a fullscreen - // popup window, minimize it before displaying an error - HWND appWindow = GetActiveWindow(); - if ( ((GetWindowLong(appWindow, GWL_STYLE) & WS_POPUP) != 0) ) - SetWindowPos( - appWindow, - HWND_NOTOPMOST, - 0, 0, // position - 0, 0, // size - SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE - ); -#endif -} - /////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/CoreLib/hsUtils.cpp b/Sources/Plasma/CoreLib/hsUtils.cpp index 60a37f3f..ba7f085a 100644 --- a/Sources/Plasma/CoreLib/hsUtils.cpp +++ b/Sources/Plasma/CoreLib/hsUtils.cpp @@ -70,6 +70,31 @@ char *hsScalarToStr(float s) return hsStrBuf; } +class hsMinimizeClientGuard +{ +#ifdef CLIENT + hsWindowHndl fWnd; + +public: + hsMinimizeClientGuard() + { +#ifdef HS_BUILD_FOR_WIN32 + fWnd = GetActiveWindow(); + // If the application's topmost window is fullscreen, minimize it before displaying an error + if ((GetWindowLong(fWnd, GWL_STYLE) & WS_POPUP) != 0) + ShowWindow(fWnd, SW_MINIMIZE); +#endif // HS_BUILD_FOR_WIN32 + } + + ~hsMinimizeClientGuard() + { +#ifdef HS_BUILD_FOR_WIN32 + ShowWindow(fWnd, SW_RESTORE); +#endif // HS_BUILD_FOR_WIN32 + } +#endif // CLIENT +}; + bool hsMessageBox_SuppressPrompts = false; int hsMessageBoxWithOwner(void * owner, const char message[], const char caption[], int kind, int icon) @@ -106,9 +131,7 @@ int hsMessageBoxWithOwner(void * owner, const char message[], const char caption else flags |= MB_ICONERROR; -#ifdef CLIENT - ErrorMinimizeAppWindow(); -#endif + hsMinimizeClientGuard guard; int ans = MessageBox((HWND)owner, message, caption, flags); switch (ans) @@ -160,9 +183,7 @@ int hsMessageBoxWithOwner(void * owner, const wchar_t message[], const wchar_t c else flags |= MB_ICONERROR; -#ifdef CLIENT - ErrorMinimizeAppWindow(); -#endif + hsMinimizeClientGuard guard; int ans = MessageBoxW((HWND)owner, message, caption, flags); switch (ans) diff --git a/Sources/Plasma/CoreLib/hsUtils.h b/Sources/Plasma/CoreLib/hsUtils.h index 0559c4be..64733ae9 100644 --- a/Sources/Plasma/CoreLib/hsUtils.h +++ b/Sources/Plasma/CoreLib/hsUtils.h @@ -217,7 +217,6 @@ hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc); void ErrorEnableGui (bool enabled); void ErrorAssert (int line, const char file[], const char fmt[], ...); -void ErrorMinimizeAppWindow (); bool DebugIsDebuggerPresent (); void DebugBreakIfDebuggerPresent ();