Skip to content

Commit

Permalink
Only set foreground if not already in foreground
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Sep 11, 2024
1 parent b2a13dd commit 641bfc0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7134
#define BUILD_NUMBER 7135
41 changes: 26 additions & 15 deletions d3d9/IDirect3D9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,21 +619,6 @@ void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight, bool isW
// Set window active and focus
if (Config.EnableWindowMode || isWindowed)
{
DWORD currentThreadId = GetCurrentThreadId();
DWORD foregroundThreadId = GetWindowThreadProcessId(GetForegroundWindow(), NULL);

// Attach the input of the foreground window and current window
AttachThreadInput(currentThreadId, foregroundThreadId, TRUE);

// Set the window as the foreground window and active
SetForegroundWindow(MainhWnd);
SetFocus(MainhWnd);
SetActiveWindow(MainhWnd);
BringWindowToTop(MainhWnd);

// Detach the input from the foreground window
AttachThreadInput(currentThreadId, foregroundThreadId, FALSE);

// Move window to top if not already topmost
LONG lExStyle = GetWindowLong(MainhWnd, GWL_EXSTYLE);
if (!(lExStyle & WS_EX_TOPMOST))
Expand All @@ -643,6 +628,32 @@ void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight, bool isW
SetWindowLong(MainhWnd, GWL_EXSTYLE, lExStyle & ~WS_EX_TOPMOST);
SetWindowPos(MainhWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
}

// Set active and foreground if needed
if (MainhWnd != GetForegroundWindow() || MainhWnd != GetFocus() || MainhWnd != GetActiveWindow())
{
DWORD currentThreadId = GetCurrentThreadId();
DWORD foregroundThreadId = GetWindowThreadProcessId(GetForegroundWindow(), NULL);

bool isForeground = (MainhWnd == GetForegroundWindow()) || (currentThreadId == foregroundThreadId);

// Attach the input of the foreground window and current window
if (!isForeground)
{
AttachThreadInput(currentThreadId, foregroundThreadId, TRUE);
SetForegroundWindow(MainhWnd);
}

SetFocus(MainhWnd);
SetActiveWindow(MainhWnd);
BringWindowToTop(MainhWnd);

// Detach the input from the foreground window
if (!isForeground)
{
AttachThreadInput(currentThreadId, foregroundThreadId, FALSE);
}
}
}

// Get screen width and height
Expand Down

0 comments on commit 641bfc0

Please sign in to comment.