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 ();