]> Cypherpunks repositories - gostls13.git/commitdiff
syscall : add a field to ProcAttr so that StartProcess can hide the executed applicat...
authorVincent Vanackere <vincent.vanackere@gmail.com>
Thu, 21 Apr 2011 14:12:06 +0000 (00:12 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 21 Apr 2011 14:12:06 +0000 (00:12 +1000)
The SW_HIDE parameter looks like the only way for a windows GUI application to execute a CLI subcommand without having a shell windows appearing.

R=brainman, golang-dev, bradfitzgo, rsc1
CC=golang-dev
https://golang.org/cl/4439055

src/pkg/syscall/exec_windows.go
src/pkg/syscall/ztypes_windows_386.go

index ce855f5bc1944f644f4f9d6054995b1aef8c8c1f..85b1c2edaa73dec6f3bbb01a0d134af15a7cc57e 100644 (file)
@@ -218,9 +218,10 @@ func joinExeDirAndFName(dir, p string) (name string, err int) {
 }
 
 type ProcAttr struct {
-       Dir   string
-       Env   []string
-       Files []int
+       Dir        string
+       Env        []string
+       Files      []int
+       HideWindow bool
 }
 
 var zeroAttributes ProcAttr
@@ -282,6 +283,10 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int,
        si := new(StartupInfo)
        si.Cb = uint32(unsafe.Sizeof(*si))
        si.Flags = STARTF_USESTDHANDLES
+       if attr.HideWindow {
+               si.Flags |= STARTF_USESHOWWINDOW
+               si.ShowWindow = SW_HIDE
+       }
        si.StdInput = fd[0]
        si.StdOutput = fd[1]
        si.StdErr = fd[2]
index 56d4198dce40ba5d9b04eab3396abf9185f639ab..3a50be14c367b1450c2a1316c2604efcb2084806 100644 (file)
@@ -77,6 +77,7 @@ const (
 
        HANDLE_FLAG_INHERIT    = 0x00000001
        STARTF_USESTDHANDLES   = 0x00000100
+       STARTF_USESHOWWINDOW   = 0x00000001
        DUPLICATE_CLOSE_SOURCE = 0x00000001
        DUPLICATE_SAME_ACCESS  = 0x00000002
 
@@ -240,6 +241,25 @@ type ByHandleFileInformation struct {
        FileIndexLow       uint32
 }
 
+// ShowWindow constants
+const (
+       // winuser.h
+       SW_HIDE            = 0
+       SW_NORMAL          = 1
+       SW_SHOWNORMAL      = 1
+       SW_SHOWMINIMIZED   = 2
+       SW_SHOWMAXIMIZED   = 3
+       SW_MAXIMIZE        = 3
+       SW_SHOWNOACTIVATE  = 4
+       SW_SHOW            = 5
+       SW_MINIMIZE        = 6
+       SW_SHOWMINNOACTIVE = 7
+       SW_SHOWNA          = 8
+       SW_RESTORE         = 9
+       SW_SHOWDEFAULT     = 10
+       SW_FORCEMINIMIZE   = 11
+)
+
 type StartupInfo struct {
        Cb            uint32
        _             *uint16