diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp index ae10cae7..00051c23 100644 --- a/src/d3d9/d3d9_swapchain.cpp +++ b/src/d3d9/d3d9_swapchain.cpp @@ -14,6 +14,7 @@ namespace dxvk { bool unicode; bool filter; WNDPROC proc; + D3D9SwapChainEx* swapchain; }; @@ -82,7 +83,7 @@ namespace dxvk { } - void HookWindowProc(HWND window) { + void HookWindowProc(HWND window, D3D9SwapChainEx* swapchain) { std::lock_guard lock(g_windowProcMapMutex); ResetWindowProc(window); @@ -94,6 +95,7 @@ namespace dxvk { CallCharsetFunction( SetWindowLongPtrW, SetWindowLongPtrA, windowData.unicode, window, GWLP_WNDPROC, reinterpret_cast(D3D9WindowProc))); + windowData.swapchain = swapchain; g_windowProcMap[window] = std::move(windowData); } @@ -124,6 +126,27 @@ namespace dxvk { if (message == WM_DESTROY) ResetWindowProc(window); + else if (message == WM_ACTIVATEAPP) { + D3DDEVICE_CREATION_PARAMETERS create_parms; + windowData.swapchain->GetDevice()->GetCreationParameters(&create_parms); + + if (!(create_parms.BehaviorFlags & D3DCREATE_NOWINDOWCHANGES)) { + if (wparam) { + // Heroes of Might and Magic V needs this to resume drawing after a focus loss + D3DPRESENT_PARAMETERS params; + RECT rect; + + GetMonitorRect(GetDefaultMonitor(), &rect); + windowData.swapchain->GetPresentParameters(¶ms); + SetWindowPos(window, nullptr, rect.left, rect.top, params.BackBufferWidth, params.BackBufferHeight, + SWP_NOACTIVATE | SWP_NOZORDER); + } + else { + if (IsWindowVisible(window)) + ShowWindow(window, SW_MINIMIZE); + } + } + } return CallCharsetFunction( CallWindowProcW, CallWindowProcA, unicode, @@ -1398,7 +1421,7 @@ namespace dxvk { // Some games restore window styles after we have changed it, so hooking is // also required. Doing it will allow us to create fullscreen windows // regardless of their style and it also appears to work on Windows. - HookWindowProc(m_window); + HookWindowProc(m_window, this); D3D9WindowMessageFilter filter(m_window);