Skip to content

Commit

Permalink
One may want to be able to set the visibility of the called process, …
Browse files Browse the repository at this point in the history
…or even not set it all because this has consequences on the first ShowWindow call that the created process will do (see MSDN for details)
  • Loading branch information
obones committed May 17, 2018
1 parent 5ce3ee1 commit 267c312
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jcl/source/common/JclSysUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ function Execute(const CommandLine: string; AbortEvent: TJclEvent;
type
{$IFDEF MSWINDOWS}
TJclExecuteCmdProcessOptionBeforeResumeEvent = procedure(const ProcessInfo: TProcessInformation) of object;
TStartupVisibility = (svHide, svShow, svNotSet);
{$ENDIF MSWINDOWS}

TJclExecuteCmdProcessOptions = {record} class(TObject)
Expand All @@ -545,6 +546,7 @@ function Execute(const CommandLine: string; AbortEvent: TJclEvent;
FAutoConvertOem: Boolean;
{$IFDEF MSWINDOWS}
FCreateProcessFlags: DWORD;
FStartupVisibility: TStartupVisibility;
FBeforeResume: TJclExecuteCmdProcessOptionBeforeResumeEvent;
{$ENDIF MSWINDOWS}

Expand All @@ -569,6 +571,7 @@ function Execute(const CommandLine: string; AbortEvent: TJclEvent;
property AutoConvertOem: Boolean read FAutoConvertOem write FAutoConvertOem default True;
{$IFDEF MSWINDOWS}
property CreateProcessFlags: DWORD read FCreateProcessFlags write FCreateProcessFlags;
property StartupVisibility: TStartupVisibility read FStartupVisibility write FStartupVisibility;
property BeforeResume: TJclExecuteCmdProcessOptionBeforeResumeEvent read FBeforeResume write FBeforeResume;
{$ENDIF MSWINDOWS}

Expand Down Expand Up @@ -2992,6 +2995,8 @@ function ExecuteCmdProcess(Options: TJclExecuteCmdProcessOptions): Boolean;
OutPipeInfo, ErrorPipeInfo: TPipeInfo;
Index: Cardinal;
{$IFDEF MSWINDOWS}
const
StartupVisibilityFlags: array[TStartupVisibility] of DWORD = (SW_HIDE, SW_SHOW, SW_SHOWDEFAULT);
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Expand Down Expand Up @@ -3043,8 +3048,12 @@ function ExecuteCmdProcess(Options: TJclExecuteCmdProcessOptions): Boolean;

ResetMemory(StartupInfo, SizeOf(TStartupInfo));
StartupInfo.cb := SizeOf(TStartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
StartupInfo.wShowWindow := SW_HIDE;
StartupInfo.dwFlags := STARTF_USESTDHANDLES;
if Options.StartupVisibility <> svNotSet then
begin
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := StartupVisibilityFlags[Options.StartupVisibility];
end;
StartupInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);
StartupInfo.hStdOutput := OutPipeInfo.PipeWrite;
if Options.MergeError then
Expand Down

0 comments on commit 267c312

Please sign in to comment.