r5sdk/r5dev/windows/window.cpp

31 lines
1.0 KiB
C++
Raw Normal View History

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