Jump to content

Look for multiple text items when finding a window


Go to solution Solved by Nine,

Recommended Posts

In the standard window-finding functions such as WinGetHandle, WinWait, WinExists, etc. where you specify the Title and Text as parameters, how do you look for multiple consecutive bits of text in the Text parameter?

Example: A window has a number of buttons with text on it and the WindowInfo tool shows the visible text for the window to contain:

Load
Save
Delete
Copy

I can specify any single one of these items as the Text parameter (i.e. 'Save'), but how would the the Text parameter of a WinGetHandle function need to be written to look for all of these items? I've tried the following without success:

WinGetHandle("Some App", "LoadSaveDeleteCopy")

WinGetHandle("Some App", "Load Save Delete Copy")

WinGetHandle("Some App", "Load|Save|Delete|Copy")

WinGetHandle("Some App", "Load" & @LF & "Save" & @LF & "Delete" & @LF & "Copy")

WinGetHandle("Some App", "Load" & @CR & "Save" & @CR & "Delete" & @CR & "Copy")

WinGetHandle("Some App", "Load" & @CRLF & "Save" & @CRLF & "Delete" & @CRLF & "Copy")

WinGetHandle("Some App", "Load" & @TAB & "Save" & @TAB & "Delete" & @TAB & "Copy")

If I do a WinGetText function on the window, it returns the above text with @LF separating the items. So it would seem like looking for them with @LF separating them would work, but it does not.

Link to comment
Share on other sites

  • Solution

Here one way :

Local $hWnd = WinGetHandleEX("You apps here", "Search|Open|Reset")
ConsoleWrite($hWnd & @CRLF)

Func WinGetHandleEX($sTitle, $sText)
  Local $aList = StringSplit($sText, "|")
  Local $aWin = WinList($sTitle)
  For $i = 1 To $aWin[0][0]
    $sGetText = WinGetText($aWin[$i][1])
    For $j = 1 to $aList[0]
      If Not StringInStr($sGetText, $aList[$j]) Then ContinueLoop 2
    Next
    Return $aWin[$i][1]
  Next
EndFunc

 

Link to comment
Share on other sites

4 hours ago, Danp2 said:

Can you explain why you need to detect the text on each button when locating a window?

It's  a matter of making sure I have the correct window. The window's title and text are commonly used as identifiers in the Win... functions, as the help info states:

 

Quote

 

Window Text

The window text consists of all the text that AutoIt can "see". This will usually be things like the contents of edit controls (as above with "This is some text!") but will also include other text like:

  • Button text like &Yes, &No, &Next (the & indicates an underlined letter)
  • Dialog text like "Are you sure you wish to continue?"
  • Control text
  • Misc text - sometimes you don't know what it is :)

The important thing is that you can use the text along with the title to uniquely identify a window to work with.

 

 

In this case, the cumulative window text includes text from a number of controls. It's the combination of text on the window that uniquely identifies it as the "right" window I'm looking for. But I haven't been able to find a way to specify the text parameter in the Win... functions so that it can match window text coming from multiple sources on the window.

Link to comment
Share on other sites

look at the example above you. if you know where the exe comes from that makes the window appear, you can look at the properties of the process and KNOW that is your window, verify by getting a handle and checking the controls

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

1 hour ago, Nine said:

Here one way :

Local $hWnd = WinGetHandleEX("You apps here", "Search|Open|Reset")
ConsoleWrite($hWnd & @CRLF)

Func WinGetHandleEX($sTitle, $sText)
  Local $aList = StringSplit($sText, "|")
  Local $aWin = WinList($sTitle)
  For $i = 1 To $aWin[0][0]
    $sGetText = WinGetText($aWin[$i][1])
    For $j = 1 to $aList[0]
      If Not StringInStr($sGetText, $aList[$j]) Then ContinueLoop 2
    Next
    Return $aWin[$i][1]
  Next
EndFunc

 

Thanks. I had thought about writing a custom function, but was hoping I was just missing some little detail that would let the built-in functions work. And was thinking that it would be necessary to write an extender function for each of the Win... functions.

But upon reflection, since a custom function like this returns the handle, it could be nested inside the calls to any of the other Win.. functions, like this:

Local $Result = WinGetState(WinGetHandleEX("Some App", "Load|Save|Delete|Copy"))

Not as easy as if the built-in functions could handle it natively, but a solution nonetheless.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...