Add 'ForceForegroundWindow' windows utility

Forces the window handle to be on top.
This commit is contained in:
Kawe Mazidjatari 2023-07-31 23:43:00 +02:00
parent 5c05f91891
commit c059ec65ac
2 changed files with 33 additions and 0 deletions

30
r5dev/windows/window.cpp Normal file
View File

@ -0,0 +1,30 @@
//=============================================================================//
//
// Purpose: Windows window procedure utilities
//
//=============================================================================//
#include "window.h"
//-----------------------------------------------------------------------------
// Purpose: forces the window handle to the front
// Input : hwnd -
// Output : non-zero on success, null otherwise
//-----------------------------------------------------------------------------
BOOL ForceForegroundWindow(HWND hwnd)
{
BOOL ret = TRUE;
DWORD windowThreadProcessId = GetWindowThreadProcessId(GetForegroundWindow(), LPDWORD(0));
DWORD currentThreadId = GetCurrentThreadId();
if (!AttachThreadInput(windowThreadProcessId, currentThreadId, true))
ret = FALSE;
if (!BringWindowToTop(hwnd))
ret = FALSE;
if (!ShowWindow(hwnd, SW_SHOW))
ret = FALSE;
if (!AttachThreadInput(windowThreadProcessId, currentThreadId, false))
ret = FALSE;
return ret;
}

3
r5dev/windows/window.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
BOOL ForceForegroundWindow(HWND hwnd);