Jump to content

Getting Windows Title using the following:


Recommended Posts

How do I get a Window's Title (that is randomized) if I know the following:

1. The folder where the exe is installed

2. Several buttons on the app are "sorta" unique from other apps. 

Initially, I thought of using 

func _FindProcess($folder)  ;find 1st running process coming from $folder
    local $PID
    local $list = _FileListToArray($folder, "*.exe", 1, false)  ;get only files, return filanames only
    if @error = 0 then
        for $i = 1 to $list[0]
            ;$list[0] = Number of Files\Folders returned
            ;$list[$i] = 1st File\Folder
            $PID = ProcessExists($list[$i])
            if $PID > 0 then return $PID
        next
    endif
    return -1
endfunc

func _FindHWND($text)
    local $list = WinList() ;get a list of every window
    for $i = 1 to $list[0][0]
        ;$list[0][0] = Number of windows returned
        ;$list[$i][0] = window title
        ;$list[$i][1] = window handle (HWND)
        if ControlGetHandle($list[$i][1], "", $text) <> 0 then
            return $list[$i][1]
        endif
    next
    return -1
endfunc

Are there any simpler method to accomplish the task?
1. To get the Window's Title or PID, I prefer Title as I can use that with ControlSend() to automate clicking a button as needed by #2 below.

2. To get the handle to specific buttons on this app

thanks

Dan

 

 

Link to post
Share on other sites

Perhaps, "random" was not a accurate word.

Notepad.exe when it runs, it's Title is "Untitled - Notepad"

When it loads "config.ini", the title becomes "config.ini - Notepad", etc... However, I do not have knowledge what file it opens, so i cannot predict using "[Title:This FileName - Notepad]"

 

BUT I do not want to get the Handle of any other app that opens this file (example, VSC opening the same file); I only am interested in notepad.exe opening a random file. 

My problem boils down to:

1. Converting PID into HWND, or TITLE. 

2. So i can use that value into ControlSend() and ControlGetText() functions.

 

Dan.

Link to post
Share on other sites

Thanks for the help.

This topic are abundant in this forum for many years and are still relevant.
There are functions for converting between Window Title and Window Handle, or getting the PID from those.
But there is no function converting PID to Window Title/Window Handle.
 

I thought, Autoit revisions would had added that function already but it is not.

I ended up looping through the WinList() checking if WinGetProcess matches with the PID I had (instead of using an unreliable checking for specific buttons as posted)...

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...