From fef2598e5f4fcd6392f9151ca253472f376483d6 Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 8 May 2016 20:03:46 +0200 Subject: [PATCH] Do not minimize on deactivation if DDSCL_NOWINDOWCHANGES is set Fixes alt-tabbing issues in Age of Wonders 2 that was making it difficult to properly activate the minimized game. --- DDrawCompat/CompatActivateAppHandler.cpp | 48 +++++++++++++++--------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/DDrawCompat/CompatActivateAppHandler.cpp b/DDrawCompat/CompatActivateAppHandler.cpp index bc59a29..dca2c3c 100644 --- a/DDrawCompat/CompatActivateAppHandler.cpp +++ b/DDrawCompat/CompatActivateAppHandler.cpp @@ -17,6 +17,35 @@ namespace void handleActivateApp(bool isActivated); + void activateApp(IDirectDraw7& dd) + { + CompatDirectDraw::s_origVtable.SetCooperativeLevel( + &dd, g_fullScreenCooperativeWindow, g_fullScreenCooperativeFlags); + if (CompatPrimarySurface::isDisplayModeChanged) + { + const CompatPrimarySurface::DisplayMode& dm = CompatPrimarySurface::displayMode; + CompatDirectDraw::s_origVtable.SetDisplayMode( + &dd, dm.width, dm.height, 32, dm.refreshRate, 0); + } + CompatGdi::enableEmulation(); + } + + void deactivateApp(IDirectDraw7& dd) + { + CompatGdi::disableEmulation(); + if (CompatPrimarySurface::isDisplayModeChanged) + { + CompatDirectDraw::s_origVtable.RestoreDisplayMode(&dd); + } + CompatDirectDraw::s_origVtable.SetCooperativeLevel( + &dd, g_fullScreenCooperativeWindow, DDSCL_NORMAL); + + if (!(g_fullScreenCooperativeFlags & DDSCL_NOWINDOWCHANGES)) + { + ShowWindow(g_fullScreenCooperativeWindow, SW_SHOWMINNOACTIVE); + } + } + LRESULT CALLBACK callWndProc(int nCode, WPARAM wParam, LPARAM lParam) { auto ret = reinterpret_cast(lParam); @@ -48,26 +77,11 @@ namespace if (isActivated) { - CompatDirectDraw::s_origVtable.SetCooperativeLevel( - dd, g_fullScreenCooperativeWindow, g_fullScreenCooperativeFlags); - if (CompatPrimarySurface::isDisplayModeChanged) - { - const CompatPrimarySurface::DisplayMode& dm = CompatPrimarySurface::displayMode; - CompatDirectDraw::s_origVtable.SetDisplayMode( - dd, dm.width, dm.height, 32, dm.refreshRate, 0); - } - CompatGdi::enableEmulation(); + activateApp(*dd); } else { - CompatGdi::disableEmulation(); - if (CompatPrimarySurface::isDisplayModeChanged) - { - CompatDirectDraw::s_origVtable.RestoreDisplayMode(dd); - } - CompatDirectDraw::s_origVtable.SetCooperativeLevel( - dd, g_fullScreenCooperativeWindow, DDSCL_NORMAL); - ShowWindow(g_fullScreenCooperativeWindow, SW_MINIMIZE); + deactivateApp(*dd); } CompatDirectDraw::s_origVtable.Release(dd);