r5sdk/r5dev/windows/window.cpp
Kawe Mazidjatari c059ec65ac Add 'ForceForegroundWindow' windows utility
Forces the window handle to be on top.
2023-07-31 23:43:00 +02:00

31 lines
1.0 KiB
C++

//=============================================================================//
//
// 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;
}