Merge pull request #400 from DanielGibson/wrapper-foreground

quake2.exe wrapper puts Q2 window in foreground
This commit is contained in:
Yamagi 2019-05-09 18:12:31 +02:00 committed by GitHub
commit 33bfd28ebc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,6 +31,26 @@
static const WCHAR WRAPPED_EXE[] = L"yquake2.exe";
// the struct and OnGetWindowByProcess taken from https://stackoverflow.com/a/17166455
typedef struct {
DWORD pid;
HWND hwnd;
} WINDOWPROCESSINFO;
static BOOL CALLBACK OnGetWindowByProcess(HWND hwnd, LPARAM lParam)
{
WINDOWPROCESSINFO *infoPtr = (WINDOWPROCESSINFO *)lParam;
DWORD check = 0;
BOOL br = TRUE;
GetWindowThreadProcessId(hwnd, &check);
if (check == infoPtr->pid)
{
infoPtr->hwnd = hwnd;
br = FALSE;
}
return br;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WCHAR* cmdLine = GetCommandLineW();
@ -83,6 +103,22 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return 1;
}
Sleep(1000); // wait until yq2 should have created the window
// send window to foreground, as shown in https://stackoverflow.com/a/17166455
// first we need to get its HWND
WINDOWPROCESSINFO info;
info.pid = GetProcessId(pi.hProcess);
info.hwnd = 0;
AllowSetForegroundWindow(info.pid);
EnumWindows(OnGetWindowByProcess, (LPARAM)&info);
if (info.hwnd != 0)
{
SetForegroundWindow(info.hwnd);
SetActiveWindow(info.hwnd);
}
// wait for wrapped exe to exit
WaitForSingleObject(pi.hProcess, INFINITE);