From 267c31214576fb53e49eb487ea4f4f336b394f4a Mon Sep 17 00:00:00 2001 From: obones Date: Thu, 17 May 2018 11:02:40 +0200 Subject: [PATCH] One may want to be able to set the visibility of the called process, 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) --- jcl/source/common/JclSysUtils.pas | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jcl/source/common/JclSysUtils.pas b/jcl/source/common/JclSysUtils.pas index 61a7f8e3de..5c84b14d6a 100644 --- a/jcl/source/common/JclSysUtils.pas +++ b/jcl/source/common/JclSysUtils.pas @@ -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) @@ -545,6 +546,7 @@ function Execute(const CommandLine: string; AbortEvent: TJclEvent; FAutoConvertOem: Boolean; {$IFDEF MSWINDOWS} FCreateProcessFlags: DWORD; + FStartupVisibility: TStartupVisibility; FBeforeResume: TJclExecuteCmdProcessOptionBeforeResumeEvent; {$ENDIF MSWINDOWS} @@ -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} @@ -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; @@ -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