I have been trying both ShellExecute and CreateProcess to Launch a game - My goal is to hide the game window. The game is built using DirectX9. For some reason I am struggling on this issue. I am using the following codes independently but without success
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = app_exe; // Path to game
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
And with CreateProcess
ZeroMemory(&procInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
startupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
startupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
startupInfo.wShowWindow = SW_HIDE;
CreateProcess(app_exe, cmdline, NULL, NULL, FALSE,CREATE_NO_WINDOW , NULL, NULL,&startupInfo, &procInfo);
WaitForSingleObject(procInfo.hProcess, INFINITE);
In both cases the game is launched and I get a full-screen game. Is there anything wrong that I am doing?
The STARTUPINFO.wShowWindow flag ends up in WinMain as the final parameter nCmdShow (https://msdn.microsoft.com/en-us/library/windows/desktop/ff381406(v=vs.85).aspx). There is no requirement that the created process adheres to this request. It is free to create as many visible windows as it likes. In fact, it's commonplace to completely ignore this flag. If you have the source code to the application being launched, and can recompile it, you could make it respect this request.
Also, I haven't tried it, but I would think that attempting to hide a DirectX fullscreen window will likely fail, and/or cause issues.