> Any suggestions to force this window to the top of all other windows? My GUI (code that I cannot change) may be pushing a cmd window to the top as I am using popen/pclose and windows starts a cmd window when you use pipes.
You won't have luck using popen() on windows, it's a very weak implementation.
It's best to reimplement its functionality using a combo of WIN32 API functions
CreatePipe() to create the in & out pipes, and assign those to STARTUPINFO
as the hStdInput and hStdOutput/hStdError members, and then pass the STARTUPINFO
to CreateProcess().
It's a bit of work to do so, but I've found it to work reliably, and no DOS window.
--- snip
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
[..]
HANDLE stdinReadPipe = 0;
HANDLE stdinWritePipe = 0;
if ( CreatePipe(&stdinReadPipe, &stdinWritePipe, &sa, 0) == 0 ) { ..error.. }
HANDLE stdoutReadPipe = 0;
HANDLE stdoutWritePipe = 0;
if ( CreatePipe(&stdoutReadPipe, &stdoutWritePipe, &sa, 0) == 0 ) { ..error.. }
STARTUPINFO si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE; // <-- yoo hoo
si.hStdInput = stdinReadPipe;
si.hStdOutput = stdoutWritePipe;
si.hStdError = stdoutWritePipe;
[..]
if (CreateProcess(NULL, // app name
(char*)cmd, // command to exec
NULL, // proc secure attribs
NULL, // thread secure attribs
TRUE, // handle inheritence
CREATE_NEW_PROCESS_GROUP, // creation flags
NULL, // environ block
NULL, // current dir
&si, // startup info
&pi)) // process info
{
// OK - Parent: close pipes we're not interested in.
// Only interested in stdoutReadPipe to get stdout/err from child.
//
if ( stdinReadPipe != 0 ) { CloseHandle(stdinReadPipe); stdinReadPipe = 0; fdstdin = 0; } // fdstdin + stdinReadPipe same
if ( stdinWritePipe != 0 ) { CloseHandle(stdinWritePipe); stdinWritePipe = 0; }
if ( stdoutWritePipe != 0 ) { CloseHandle(stdoutWritePipe); stdoutWritePipe = 0; }
[..]
}
else
{
..error..
if ( stdinReadPipe != 0 ) { CloseHandle(stdinReadPipe); stdinReadPipe = 0; }
if ( stdinWritePipe != 0 ) { CloseHandle(stdinWritePipe); stdinWritePipe = 0; }
if ( stdoutWritePipe != 0 ) { CloseHandle(stdoutWritePipe); stdoutWritePipe = 0; }
}
--- snip