AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is there a reason why winGet returns different values?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
scribbly



Joined: 24 Apr 2009
Posts: 9

PostPosted: Tue Oct 13, 2009 12:30 am    Post subject: Is there a reason why winGet returns different values? Reply with quote

Consider the snippet:

Code:
   Run, %programme_to_run%, , UseErrorLevel, cmd_PID
   WinWait ahk_pid %cmd_PID%,,10
   if not ERRORLEVEL
   {
      WinGet, win_ID, ID, ahk_pid %cmd_PID%
      if !win_ID
         MsgBox, No matching windows
      unique:= winexist(ahk_pid %cmd_PID%)
     WinGet, active, ID, A
   }
   else
      MsgBox, Errow waiting for ahk_pid %cmd_PID%
      
   MsgBox, %win_ID%`n%unique%`n%active%


Why can the three values be different (apart from the window not being active)??

What I thought would be easy was to get the windowID from the ProcessID returned from Run and close it later... but the close fails because the Win_ID is usually not set to the same value as active.

Any ideas?
_________________
Scribbly
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Tue Oct 13, 2009 1:37 am    Post subject: Reply with quote

to use pid you have to have full path to exe
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
scribbly



Joined: 24 Apr 2009
Posts: 9

PostPosted: Tue Oct 13, 2009 2:20 am    Post subject: Reply with quote

ahklerner wrote:
to use pid you have to have full path to exe


Thanks: where do you mean? %programme_to_run% is the full path, and Run returns the correct PID.

WinWait ahk_pid %cmd_PID% finds a window OK

WinGet, win_ID, ID, ahk_pid %cmd_PID% does not return the same ID that WinGet, active, ID, A returns (when the appropriate window is active).
_________________
Scribbly
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Tue Oct 13, 2009 2:43 am    Post subject: Reply with quote

perhaps the program you are running is creating multiple windows ? (you may not be able to see all of them) in that case also specify a window title or something like My Window Title ahk_pid %pid% ... iirc somewhere i read that if there are multiple windows that match the wintitle parameter, it returns the info for the topmost.
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
scribbly



Joined: 24 Apr 2009
Posts: 9

PostPosted: Tue Oct 13, 2009 3:01 am    Post subject: Reply with quote

ahklerner wrote:
perhaps the program you are running is creating multiple windows ? (you may not be able to see all of them) in that case also specify a window title or something like My Window Title ahk_pid %pid% ... iirc somewhere i read that if there are multiple windows that match the wintitle parameter, it returns the info for the topmost.


Thanks for the pointer:
Code:
Get, NumberWindows, List, ahk_pid %cmd_PID%


is very revealing! Smile

Plus it helps if you turn off DetectHiddenWindows Embarassed
_________________
Scribbly
Back to top
View user's profile Send private message
temp01



Joined: 09 Jul 2009
Posts: 120

PostPosted: Tue Oct 13, 2009 2:19 pm    Post subject: Re: Is there a reason why winGet returns different values? Reply with quote

BTW,
scribbly wrote:
Code:
...
      unique:= winexist(ahk_pid %cmd_PID%)
...

should be
Code:
      unique:= winexist("ahk_pid " . cmd_PID)
Back to top
View user's profile Send private message
scribbly



Joined: 24 Apr 2009
Posts: 9

PostPosted: Tue Oct 13, 2009 9:55 pm    Post subject: Re: Is there a reason why winGet returns different values? Reply with quote

temp01 wrote:
BTW,
scribbly wrote:
Code:
...
      unique:= winexist(ahk_pid %cmd_PID%)
...

should be
Code:
      unique:= winexist("ahk_pid " . cmd_PID)


Yes, of course: thanks.

I presume that WinExists() was returning the top-most, or last opened, window?
_________________
Scribbly
Back to top
View user's profile Send private message
temp01



Joined: 09 Jul 2009
Posts: 120

PostPosted: Tue Oct 13, 2009 10:11 pm    Post subject: Re: Is there a reason why winGet returns different values? Reply with quote

scribbly wrote:
I presume that WinExists() was returning the top-most, or last opened, window?


It was returning the last found found.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group