WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: USMuscle on August 17, 2016, 12:37:13 PM

Title: Get the Name of a Window I Just Opened
Post by: USMuscle on August 17, 2016, 12:37:13 PM
I'd like to open an Explorer window in a specific size and location. Since I can't think of a function that does this, I've been approaching it from the standpoint of opening the window, then using WinPlace, but I can't seem to figure out a way to get that window name. I am familiar with WinItemNameID and those types of functions, but that doesn't seem to help me in this context because I need to know the name of the window I just opened. Does anyone know a way to do this?

Thank you.
Title: Re: Get the Name of a Window I Just Opened
Post by: td on August 17, 2016, 01:21:27 PM

Examples for most of the above can be found on the forum or Tech Database.

Here is one:
http://forum.winbatch.com/index.php?topic=1650.msg8148#msg8148 (http://forum.winbatch.com/index.php?topic=1650.msg8148#msg8148)
Title: Re: Get the Name of a Window I Just Opened
Post by: td on August 17, 2016, 01:43:06 PM
Neglected to mention that your implementation choice may be influenced by whether or not the system or systems you are running your script on are configured so that each instance of Explorer runs in a separate process or in a separate thread of the same process.  Also, generally windows are enumerated in last to first created order.
Title: Re: Get the Name of a Window I Just Opened
Post by: USMuscle on August 17, 2016, 02:14:53 PM
Quote from: td on August 17, 2016, 01:43:06 PM
Neglected to mention that your implementation choice may be influenced by whether or not the system or systems you are running your script on are configured so that each instance of Explorer runs in a separate process or in a separate thread of the same process.
Good point.
QuoteAlso, generally windows are enumerated in last to first created order.
I guess this means I can look for the highest number.

I've been toying with something like the below. Different system configurations notwithstanding, in regards to your first point above, how reliable do you think something like this would be, as compared to the enumeration option you mentioned above? The one thing I have concerns about is having to wait, as indicated by the TimeDelay after the Run command. I mean, what if someone's computer is slower, as when a computer gets bogged down by some other process? I also normally try to stay away from deductive processes, but in this case, maybe...?

Code (winbatch) Select
localdir=DirHome()

#DefineFunction UDFReformat_WindowsBeforeList(list)
newlist = ""
count = ItemCount( list,"|")
count = count/2
For x = 1 To count By 2
   title= ItemExtract(x,list,"|")
   id= ItemExtract(x+1,list,"|")
   newlist = StrCat(newlist,Title,"|",id,@TAB)
Next
WindowsBefore = StrTrim(newlist)
Return WindowsBefore
#EndFunction
winlist = WinItemNameId( )
WindowsBefore=UDFReformat_WindowsBeforeList(winlist); get list of windows before opening new Explorer window

Run("explorer.exe",localdir)
TimeDelay(1)

#DefineFunction UDFReformat_WindowsAfterList(list)
newlist = ""
count = ItemCount( list,"|")
count = count/2
For x = 1 To count By 2
   title= ItemExtract(x,list,"|")
   id= ItemExtract(x+1,list,"|")
   newlist = StrCat(newlist,Title,"|",id,@TAB)
Next
WindowsAfter = StrTrim(newlist)
Return WindowsAfter
#EndFunction
winlist = WinItemNameId( )
WindowsAfter=UDFReformat_WindowsAfterList(winlist) ;get list of windows after opening new Explorer window

;Compare the windows from the "After" list with those in the "Before" list. The "After" window that is not in the "Before" list must be the Explorer window that was opened
WindowsAfterCount=ItemCount(WindowsAfter,@tab)

For xx=1 to WindowsAfterCount
ThisWindow=ItemExtract(xx,WindowsAfter,@tab)
;Message("",ThisWindow)
If StrIndexNC(WindowsBefore,ThisWindow,1,@fwdscan)==0 Then Break
Next

Position=StrIndex(ThisWindow,"|",1,@fwdscan)
ThisWindowID=StrSub(ThisWindow,Position+1,-1)
WinActivate(ThisWindowID)
Message("New Window",ThisWindow)
Title: Re: Get the Name of a Window I Just Opened
Post by: USMuscle on August 17, 2016, 03:34:30 PM
I've been looking, but can't seem to find the topics in the Tech Database pertaining to enumerating windows. Can you please tell me what phrase to search for?
Title: Re: Get the Name of a Window I Just Opened
Post by: fhammer on October 04, 2016, 10:33:03 AM
Check out the post with the title: "Window which was active when script was invoked".