ENH: Added show/hide window support.
This commit is contained in:
parent
27289e3267
commit
59d886d0f4
|
@ -54,6 +54,9 @@ int main()
|
|||
This is parsed off the command line. */
|
||||
HANDLE killEvent = 0;
|
||||
|
||||
/* Flag for whether to hide window of child process. */
|
||||
int hideWindow = 0;
|
||||
|
||||
/* An array of the handles on which we wait when the child is
|
||||
running. */
|
||||
HANDLE waitHandles[2] = {0, 0};
|
||||
|
@ -79,6 +82,11 @@ int main()
|
|||
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
||||
sscanf(cmdLine, "%p", &killEvent);
|
||||
|
||||
/* Parse the hide window flag. */
|
||||
while(*cmdLine && *cmdLine != ' ') { ++cmdLine; }
|
||||
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
||||
sscanf(cmdLine, "%d", &hideWindow);
|
||||
|
||||
/* Skip to the beginning of the command line of the real child. */
|
||||
while(*cmdLine && *cmdLine != ' ') { ++cmdLine; }
|
||||
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
||||
|
@ -88,7 +96,7 @@ int main()
|
|||
ZeroMemory(&pi, sizeof(pi));
|
||||
si.cb = sizeof(si);
|
||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||
si.wShowWindow = SW_SHOWDEFAULT;
|
||||
si.wShowWindow = hideWindow?SW_HIDE:SW_SHOWDEFAULT;
|
||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
|
|
@ -140,6 +140,9 @@ struct kwsysProcess_s
|
|||
/* The working directory for the child process. */
|
||||
char* WorkingDirectory;
|
||||
|
||||
/* Whether to hide the child process's window. */
|
||||
int HideWindow;
|
||||
|
||||
/* On Win9x platforms, the path to the forwarding executable. */
|
||||
char* Win9x;
|
||||
|
||||
|
@ -638,17 +641,21 @@ void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
|
|||
/*--------------------------------------------------------------------------*/
|
||||
int kwsysProcess_GetOption(kwsysProcess* cp, int optionId)
|
||||
{
|
||||
(void)cp;
|
||||
(void)optionId;
|
||||
return 0;
|
||||
switch(optionId)
|
||||
{
|
||||
case kwsysProcess_Option_HideWindow: return cp->HideWindow;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void kwsysProcess_SetOption(kwsysProcess* cp, int optionId, int value)
|
||||
{
|
||||
(void)cp;
|
||||
(void)optionId;
|
||||
(void)value;
|
||||
switch(optionId)
|
||||
{
|
||||
case kwsysProcess_Option_HideWindow: cp->HideWindow = value; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
@ -692,6 +699,7 @@ void kwsysProcess_Execute(kwsysProcess* cp)
|
|||
|
||||
/* Windows child startup control data. */
|
||||
STARTUPINFO si;
|
||||
DWORD dwCreationFlags=0;
|
||||
|
||||
/* Do not execute a second time. */
|
||||
if(cp->State == kwsysProcess_State_Executing)
|
||||
|
@ -761,9 +769,9 @@ void kwsysProcess_Execute(kwsysProcess* cp)
|
|||
/* The forwarding executable is given a handle to the error pipe
|
||||
and a handle to the kill event. */
|
||||
cp->RealCommand = malloc(strlen(cp->Win9x)+strlen(cp->Command)+100);
|
||||
sprintf(cp->RealCommand, "%s %p %p %s", cp->Win9x,
|
||||
cp->Pipe[CMPE_PIPE_ERROR].Write,
|
||||
cp->Win9xKillEvent, cp->Command);
|
||||
sprintf(cp->RealCommand, "%s %p %p %d %s", cp->Win9x,
|
||||
cp->Pipe[CMPE_PIPE_ERROR].Write, cp->Win9xKillEvent,
|
||||
cp->HideWindow, cp->Command);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -776,24 +784,16 @@ void kwsysProcess_Execute(kwsysProcess* cp)
|
|||
si.hStdOutput = cp->Pipe[CMPE_PIPE_STDOUT].Write;
|
||||
si.hStdError = cp->Pipe[CMPE_PIPE_STDERR].Write;
|
||||
|
||||
/* Hide the forwarding executable console on Windows 9x. */
|
||||
/* Decide whether a child window should be shown. */
|
||||
si.dwFlags |= STARTF_USESHOWWINDOW;
|
||||
if(cp->Win9x)
|
||||
{
|
||||
si.wShowWindow = SW_HIDE;
|
||||
}
|
||||
else
|
||||
{
|
||||
si.wShowWindow = SW_SHOWDEFAULT;
|
||||
}
|
||||
si.wShowWindow = cp->HideWindow?SW_HIDE:SW_SHOWDEFAULT;
|
||||
|
||||
/* The timeout period starts now. */
|
||||
cp->StartTime = kwsysProcessTimeGetCurrent();
|
||||
cp->TimeoutTime = kwsysProcessTimeFromDouble(-1);
|
||||
|
||||
/* CREATE THE CHILD PROCESS */
|
||||
if(!CreateProcess(0, cp->RealCommand, 0, 0, TRUE,
|
||||
cp->Win9x? CREATE_NEW_CONSOLE:DETACHED_PROCESS, 0,
|
||||
if(!CreateProcess(0, cp->RealCommand, 0, 0, TRUE, dwCreationFlags, 0,
|
||||
cp->WorkingDirectory, &si, &cp->ProcessInformation))
|
||||
{
|
||||
kwsysProcessCleanup(cp, 1);
|
||||
|
|
Loading…
Reference in New Issue