简体   繁体   中英

Checking if a process has a window

In my Go code, I'm starting an external GUI application (Firefox), and I'm trying to make it the front window (the top most window). After trying robotgo , I found out that it didn't work because when I called ActivePID , the window still hasn't loaded, so there wasn't a window for robotgo to set to top-most.

How can I detect when Firefox has loaded it's GUI? (in a cross-platform way)

cmd := exec.Command("firefox")
cmd.Start()
robotgo.ActivePID(int32(cmd.Process.Pid))
cmd.Wait()

If anyone also comes across this problem, I found out that robotgo has an API called robotgo.GetPID , which gets the process id of the current active window!

That means that we can repeatedly check if robotgo.GetPID returns our target process id or not:

for int32(processID) != robotgo.GetPID() {
    robotgo.ActivePID(int32(processID))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM