mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 15:21:44 +00:00
quake2.exe wrapper puts Q2 window in foreground
because it sucks when you start quake2.exe and the game starts in the background
This commit is contained in:
parent
f5d9c49f20
commit
7db5c71f3a
1 changed files with 36 additions and 0 deletions
|
@ -31,6 +31,26 @@
|
||||||
|
|
||||||
static const WCHAR WRAPPED_EXE[] = L"yquake2.exe";
|
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)
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
WCHAR* cmdLine = GetCommandLineW();
|
WCHAR* cmdLine = GetCommandLineW();
|
||||||
|
@ -83,6 +103,22 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
return 1;
|
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
|
// wait for wrapped exe to exit
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue