Jump to content

WinWaitNew_GetTitle


Ármányos Kő
 Share

Recommended Posts

I made some script which brings up different Sub-windows by keyboard shortcuts. I mean windows like Paste Special, Open, ... These windows do have different titles under different language OS.

So the question came how to manipulate these windows by title reference, if not nowing the name?

Even, how to WinWaitActive if not knowing the title?

The answer is below.

Maybe it is some use of someone.

(Basically the script in this form is a try to make a quasi-UDF, it's a bit dodgy, I am not expert in ByRef functioning yet.)

#Include <Constants.au3>
#Include <Array.au3>
#include <file.au3>
#include <GUIConstants.au3>




Func WinWaitNew_GetTitle(ByRef $NT)
    $NT = ""
    
    Do
        Sleep(50)
        $PostList = WinList()
    Until $PostList[0][0] <> $WinWaitNew_Start[0][0]
    
    For $i = 1 to $PostList[0][0]
        If $PostList[$i][0] <> "" AND IsVisible($PostList[$i][1]) Then
        $NT = $NT&$PostList[$i][0]
        EndIf
    Next

    For $i = 1 to $WinWaitNew_Start[0][0]
        If $WinWaitNew_Start[$i][0] <> "" AND IsVisible($WinWaitNew_Start[$i][1]) Then
        $NT = StringReplace($NT, $WinWaitNew_Start[$i][0],"", 1,1)
        EndIf
    Next    
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc



;Testing the functions

AutoItSetOption("WinTitleMatchMode", 2)
    $NewTitle = ""

Run("notepad.exe")
WinWaitActive("Notepad", "")
$WinWaitNew_Start = WinList()   ;Start watching right before bringing up new window with some action
Send ("^o")               ;This action brings up the new window, which we do not know the title of
WinWaitNew_GetTitle($NewTitle)  ;Get the title of the new window
MsgBox(0, "The title", "Your title of OPEN window is: "&@CRLF&@TAB&$NewTitle)
MsgBox(0, "The title", "Now you can reference to this window with $NewTitle and perform actions with ControlClick and others")

WinActivate ($NewTitle, "")
WinWaitActive( $NewTitle, "")
ControlClick ($NewTitle, "", "ComboBox2")
Sleep(1000)
ControlClick ($NewTitle, "", "ComboBox3")
Sleep(1000)
ControlClick ($NewTitle, "", "ComboBox4")
Sleep(1000)
WinClose( $NewTitle, "")
Sleep(500)
WinClose("Notepad", "")

Edit: added codetags

Edited by JdeB
Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 year later...

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...