I am trying to launch a browser window via CreateProcess.
Sometimes it is launched in the foreground. This is what I want.
Sometimes the new window is placed under all the other windows. This is not what I want.
I have followed the instructions at How to bring window on top of the process created through CreateProcess, it does not work; the results are still inconsistent.
Here is the code:
void launch(const string &url) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si);
string args = string(" ") + url;
LPSTR args_win = const_cast<char*>(args.c_str());
CreateProcess("C:/Program Files/Mozilla Firefox/firefox.exe", args_win, 0, 0, 0, 0, 0, 0, &si, &pi);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}