I have a program that has multiple instances open.
I want to retrieve the handles of each instance so that I can interact with each in my macroscheduler script. Each window has the same window name.
I was wondering if searching for window handles by window name was possible however I understand this will only retrieve the handle of the first one found.
Any other ideas?
Get window handles of multiple instances
Moderators: JRL, Dorian (MJT support)
Re: Get window handles of multiple instances
My current working script works by:
- image recognition to detect and count each instance of the window
- using this image recognition, it brings each successive window into focus and retrieves the handle using WIN_USEHANDLE=1 and GetActiveWindow.
- each successive handle is then stored in an array
I'm sure that there is a more elegant way to achieve this, however it's working nicely so far.
- image recognition to detect and count each instance of the window
- using this image recognition, it brings each successive window into focus and retrieves the handle using WIN_USEHANDLE=1 and GetActiveWindow.
- each successive handle is then stored in an array
I'm sure that there is a more elegant way to achieve this, however it's working nicely so far.
Re: Get window handles of multiple instances
If you run this script while your windows are open does each window name display in the message?
Code: Select all
GetWindowList>vList
MDL>vList
Re: Get window handles of multiple instances
Unfortunately all instances of the software/window of interest are displayed the sameJRL wrote:does each window name display in the message?
Re: Get window handles of multiple instances
I have it sorted now without using image recognition.
I end up with two arrays - one with the window names (for confirmation and debugging) and one with the handles.
Any suggestions for optimising this code or cleaning it up are always appreciated.
Tim
Code: Select all
Let>WIN_USEHANDLE=1
GetWindowList>allWindows
Separate>allWindows,CRLF,winH
let>Win_USEHANDLE=0
If>winH_count>0
Let>k=0
Let>m=0
Repeat>k
Let>k=k+1
Let>this_windowH=winH_%k%
GetWindowNames>this_windowH,strTitle,strClass
Let>substring=*WINDOWNAMEHERE*
Pos>%substring%,%strTitle%,1,posText
if>posText>0
let>m=m+1
Let>winN_%m%=%strTitle%
Let>winHandle_%m%=winH_%k%
else
endif
Until>k=winH_count
Any suggestions for optimising this code or cleaning it up are always appreciated.
Tim
Re: Get window handles of multiple instances
I see you just posted. Good job!
I had pretty much the same thing in mind. Only one list though.
I had pretty much the same thing in mind. Only one list though.
Code: Select all
Let>WindowSought=The Window Name I Seek
Let>WindowHandleList=
Let>WIN_USEHANDLE=1
GetWindowList>vList
Separate>vList,crlf,vWinHndl
Let>kk=0
Repeat>kk
Add>kk,1
Let>value=vWinHndl_%kk%
GetWindowNames>value,vTitle,vClass
If>%vTitle%=%WindowSought%
Concat>WindowHandleList,%value%%crlf%
EndIf
Until>kk=vWinHndl_Count
MDL>WindowHandleList