From 4ba4ca7fee09d4af2d44bca66fbf33565f0345f2 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 9 Jun 2012 23:24:59 -0400 Subject: [PATCH 1/2] 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 (); From 87549fceb10d355d46579078a03d700be07049cb Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 10 Jun 2012 00:09:47 -0400 Subject: [PATCH 2/2] hsMessageBoxWithOwner functions use hsWindowHndl --- Sources/Plasma/CoreLib/hsUtils.cpp | 20 ++++++-------------- Sources/Plasma/CoreLib/hsUtils.h | 4 ++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsUtils.cpp b/Sources/Plasma/CoreLib/hsUtils.cpp index ba7f085a..45e5f0e0 100644 --- a/Sources/Plasma/CoreLib/hsUtils.cpp +++ b/Sources/Plasma/CoreLib/hsUtils.cpp @@ -97,7 +97,7 @@ public: bool hsMessageBox_SuppressPrompts = false; -int hsMessageBoxWithOwner(void * owner, const char message[], const char caption[], int kind, int icon) +int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon) { if (hsMessageBox_SuppressPrompts) return hsMBoxOk; @@ -132,7 +132,7 @@ int hsMessageBoxWithOwner(void * owner, const char message[], const char caption flags |= MB_ICONERROR; hsMinimizeClientGuard guard; - int ans = MessageBox((HWND)owner, message, caption, flags); + int ans = MessageBox(owner, message, caption, flags); switch (ans) { @@ -149,7 +149,7 @@ int hsMessageBoxWithOwner(void * owner, const char message[], const char caption #endif } -int hsMessageBoxWithOwner(void * owner, const wchar_t message[], const wchar_t caption[], int kind, int icon) +int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon) { if (hsMessageBox_SuppressPrompts) return hsMBoxOk; @@ -184,7 +184,7 @@ int hsMessageBoxWithOwner(void * owner, const wchar_t message[], const wchar_t c flags |= MB_ICONERROR; hsMinimizeClientGuard guard; - int ans = MessageBoxW((HWND)owner, message, caption, flags); + int ans = MessageBoxW(owner, message, caption, flags); switch (ans) { @@ -203,20 +203,12 @@ int hsMessageBoxWithOwner(void * owner, const wchar_t message[], const wchar_t c int hsMessageBox(const char message[], const char caption[], int kind, int icon) { -#if HS_BUILD_FOR_WIN32 - return hsMessageBoxWithOwner(nil/*GetActiveWindow()*/,message,caption,kind,icon); -#else - return hsMessageBoxWithOwner(nil,message,caption,kind,icon); -#endif + return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); } int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon) { -#if HS_BUILD_FOR_WIN32 - return hsMessageBoxWithOwner(nil/*GetActiveWindow()*/,message,caption,kind,icon); -#else - return hsMessageBoxWithOwner(nil,message,caption,kind,icon); -#endif + return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); } inline hsBool hsCompare(float a, float b, float delta) diff --git a/Sources/Plasma/CoreLib/hsUtils.h b/Sources/Plasma/CoreLib/hsUtils.h index 64733ae9..8bf36fef 100644 --- a/Sources/Plasma/CoreLib/hsUtils.h +++ b/Sources/Plasma/CoreLib/hsUtils.h @@ -126,8 +126,8 @@ enum { // RETURN VALUES FROM hsMessageBox extern bool hsMessageBox_SuppressPrompts; int hsMessageBox(const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBoxWithOwner(void* owner, const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBoxWithOwner(void* owner, const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); +int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); +int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); inline hsBool hsCompare(float a, float b, float delta=0.0001);