Jump to content

_ProcessGetWinTitle


Zisly
 Share

Recommended Posts

Hello, I made a little function which I to find the title of a process windows.

;===============================================================================
;
; Description -   Returns a string containing the title of a window title of a process
; Syntax -     _ProcessGetWinTitle($SProcess,$bM)
; Parameters -  $SProcess = Process name
;                $bM = If set to true and there are multiple windows it will return
;                      an array with all titles else it will just return the last active window 
; Requirements -  None.
; Return Values - Success - The title 
;                Success - if $bM is set to true: 
;                Array[0] = Amount of titles/windows found
;
;                Failure - Blank string and sets @error
;                      1 - Process doesn't exist
; Author(s) -    Zisly
; Notes -        If there are multiple windows it will return an array if $bM is set to true
;===============================================================================
Func _ProcessGetWinTitle($SProcess, $bM = False)
    If Not ProcessExists($SProcess) Then
        SetError(1)
        Return ''
    EndIf
    
    Local $a_WinT[1] = [1]
    Local $a_Processes = ProcessList()
    Local $a_WinList = WinList()
    
    If Not @error Then
        For $i = 1 To $a_WinList[0][0]
            $i_PID = WinGetProcess($a_WinList[$i][0])
            For $o = 1 To $a_Processes[0][0]
                If $bM = True Then
                    If $a_Processes[$o][1] = $i_PID And $a_Processes[$o][0] = $SProcess Then
                        ReDim $a_WinT[$a_WinT[0] + 1]
                        $a_WinT[$a_WinT[0]] = $a_WinList[$i][0]
                        $a_WinT[0] += 1
                    EndIf
                Else
                    If $a_Processes[$o][1] = $i_PID And $a_Processes[$o][0] = $SProcess Then Return $a_WinList[$i][0]
                EndIf
            Next
        Next
        $a_WinT[0] -= 1
        Return $a_WinT
    EndIf
EndFunc  ;==>_ProcessGetWinTitle

Any tips to improve? :)

Edited by Zisly
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...