Skip to content

Commit

Permalink
Set non-exclusive windows top, active and focused
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Aug 22, 2024
1 parent 0d806b7 commit 03d5c7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 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 7102
#define BUILD_NUMBER 7103
29 changes: 25 additions & 4 deletions d3d9/IDirect3D9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WndProc hook
bool EnableWndProcHook = false;

void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight);
void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight, bool isWindowed);

HRESULT m_IDirect3D9Ex::QueryInterface(REFIID riid, void** ppvObj)
{
Expand Down Expand Up @@ -533,7 +533,7 @@ void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND
GetClientRect(DeviceDetails.DeviceWindow, &Rect);
if (AnyChange || Rect.right - Rect.left != DeviceDetails.BufferWidth || Rect.bottom - Rect.top != DeviceDetails.BufferHeight)
{
AdjustWindow(DeviceDetails.DeviceWindow, DeviceDetails.BufferWidth, DeviceDetails.BufferHeight);
AdjustWindow(DeviceDetails.DeviceWindow, DeviceDetails.BufferWidth, DeviceDetails.BufferHeight, pPresentationParameters->Windowed);
}

// Set fullscreen resolution
Expand Down Expand Up @@ -591,7 +591,7 @@ void UpdatePresentParameterForMultisample(D3DPRESENT_PARAMETERS* pPresentationPa
}

// Adjusting the window position for WindowMode
void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight)
void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight, bool isWindowed)
{
if (!IsWindow(MainhWnd) || !displayWidth || !displayHeight)
{
Expand All @@ -600,11 +600,32 @@ void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight)
}

// Set window active and focus
if (Config.EnableWindowMode)
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))
{
SetWindowLong(MainhWnd, GWL_EXSTYLE, lExStyle | WS_EX_TOPMOST);
SetWindowPos(MainhWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
SetWindowLong(MainhWnd, GWL_EXSTYLE, lExStyle & ~WS_EX_TOPMOST);
SetWindowPos(MainhWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
}
}

// Get screen width and height
Expand Down

0 comments on commit 03d5c7a

Please sign in to comment.