fix: find console window

This commit is contained in:
ShuheiKubota 2019-11-18 12:59:18 +09:00
parent e0fddf6b59
commit d0b7427efd
1 changed files with 33 additions and 15 deletions

18
vvin.go
View File

@ -48,6 +48,22 @@ func (c *globalCmd) Before() error {
}
an := ancestors()
if c.Target == "" {
loopConsole:
for _, p := range an {
for _, w := range wins {
if w.PID == p {
if c.Debug {
rog.Printf("win: %#v", w)
}
c.targetHandle = w.Handle
break loopConsole
}
}
}
} else {
t := strings.ToLower(c.Target)
for _, w := range wins {
@ -62,6 +78,7 @@ func (c *globalCmd) Before() error {
if c.Debug {
rog.Printf("win: %#v (ancestor? %v)", w, ancestor)
}
if t != "" && !ancestor {
wt := strings.ToLower(w.Title)
@ -74,6 +91,7 @@ func (c *globalCmd) Before() error {
break
}
}
}
if c.targetHandle == 0 {
return errors.New("no target")