AutoHotkey Community

It is currently May 27th, 2012, 12:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: October 13th, 2009, 1:30 am 
Offline

Joined: April 24th, 2009, 5:24 pm
Posts: 9
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 2:37 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
to use pid you have to have full path to exe

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 3:20 am 
Offline

Joined: April 24th, 2009, 5:24 pm
Posts: 9
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 3:43 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
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.

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 4:01 am 
Offline

Joined: April 24th, 2009, 5:24 pm
Posts: 9
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! :)

Plus it helps if you turn off DetectHiddenWindows :oops:

_________________
Scribbly


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 13th, 2009, 3:19 pm 
Offline

Joined: July 9th, 2009, 9:25 pm
Posts: 120
BTW,
scribbly wrote:
Code:
...
      unique:= winexist(ahk_pid %cmd_PID%)
...

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 13th, 2009, 10:55 pm 
Offline

Joined: April 24th, 2009, 5:24 pm
Posts: 9
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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 13th, 2009, 11:11 pm 
Offline

Joined: July 9th, 2009, 9:25 pm
Posts: 120
scribbly wrote:
I presume that WinExists() was returning the top-most, or last opened, window?


It was returning the last found found.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me, Pulover, rjgatito, XstatyK, Yahoo [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group