From 7ad27059c6130b341c8965098baf3e41309453a1 Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Thu, 7 Nov 2024 18:07:52 -0800 Subject: [PATCH] Conditionally send focus and activate app messages #305 --- Dllmain/BuildNo.rc | 2 +- ddraw/IDirectDrawX.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index 319f483a..05575130 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7307 +#define BUILD_NUMBER 7308 diff --git a/ddraw/IDirectDrawX.cpp b/ddraw/IDirectDrawX.cpp index 2322189a..fa533810 100644 --- a/ddraw/IDirectDrawX.cpp +++ b/ddraw/IDirectDrawX.cpp @@ -3110,6 +3110,9 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName) // Store new focus window hFocusWindow = hWnd; + // Check active + bool WndLastActive = (hWnd == GetForegroundWindow() && hWnd == GetFocus() && hWnd == GetActiveWindow()); + // Hook WndProc before creating device bool WndProcAdded = WndProc::AddWndProc(hWnd, true); @@ -3389,13 +3392,16 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName) } // Window focus and activate app - PostMessage(hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL); - PostMessage(hWnd, WM_SETFOCUS, NULL, NULL); - PostMessage(hWnd, WM_SYNCPAINT, (WPARAM)32, NULL); - PostMessage(hWnd, WM_ACTIVATEAPP, TRUE, (LPARAM)GetWindowThreadProcessId(hWnd, nullptr)); + if (!WndLastActive || LastHWnd != hFocusWindow) + { + PostMessage(hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL); + PostMessage(hWnd, WM_SETFOCUS, NULL, NULL); + PostMessage(hWnd, WM_SYNCPAINT, (WPARAM)32, NULL); + PostMessage(hWnd, WM_ACTIVATEAPP, TRUE, (LPARAM)GetWindowThreadProcessId(hWnd, nullptr)); #ifdef WM_DWMNCRENDERINGCHANGED - PostMessage(hWnd, WM_DWMNCRENDERINGCHANGED, FALSE, NULL); + PostMessage(hWnd, WM_DWMNCRENDERINGCHANGED, FALSE, NULL); #endif + } } // Store display frequency