Sign in to follow this  
Followers 0
Cha0sBG

Process Get Title

5 posts in this topic

ok this code get's the title of an application from PID but.....

it get's only 1 title

can someone edit the code so it get's all the titles if there is more than 1 process with the same name ?

ty

#include <GUIConstantsEx.au3>


#include <WindowsConstants.au3>

#include <Process.au3>
#include <Array.au3>

$exe_name = "notepad.exe"

$winlist = ProcessList ($exe_name)

GUICreate("Process2Title", 200, 28, (@DesktopWidth-200)/2, (@DesktopHeight-28)/2, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))

$combo = GUICtrlCreateCombo ("", 4,4,192,20)



For $i = 1 To $winlist[0][0]
    GUICtrlSetData ($combo, WinGetTitle(_ProcessGetWinEx($winlist[$i][0],"","","",True)))
Next

GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Exit

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "", $ivReturnOnlyFirstMatch = False)
 
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
   
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
 
    For $i = 1 To $avwArray[0][0]
        $avClass = DllCall("User32.dll", "int", "GetClassName", "hwnd", $avwArray[$i][1], "str", "", "int", 4096)
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or (IsArray($avClass) And $avClass[2] = $svClass) Then
                If ($svTitle = "" Or StringInStr($avwArray[$i][0], $svTitle)) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                    If $ivReturnOnlyFirstMatch Then
                        $avRet = $avret[1]
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
 
    Return $avRet
 
EndFunc

Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites



no one knows how ? ;(


Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites

Does this work for you?

#include <GUIConstantsEx.au3>


#include <WindowsConstants.au3>

#include <Process.au3>
#include <Array.au3>

$exe_name = "notepad.exe"

$winlist = ProcessList ($exe_name)

GUICreate("Process2Title", 200, 28, (@DesktopWidth-200)/2, (@DesktopHeight-28)/2, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))

$combo = GUICtrlCreateCombo ("", 4,4,192,20)


$setdata = ''
For $i = 1 To $winlist[0][0]
    $setdata &= WinGetTitle(_ProcessGetWinEx($winlist[$i][1],"","","",True))
    If $i <> $winlist[0][0] Then $setdata &= "|"
Next
GUICtrlSetData ($combo, $setdata )

GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Exit

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "", $ivReturnOnlyFirstMatch = False)
 
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
   
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
 
    For $i = 1 To $avwArray[0][0]
        $avClass = DllCall("User32.dll", "int", "GetClassName", "hwnd", $avwArray[$i][1], "str", "", "int", 4096)
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or (IsArray($avClass) And $avClass[2] = $svClass) Then
                If ($svTitle = "" Or StringInStr($avwArray[$i][0], $svTitle)) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                    If $ivReturnOnlyFirstMatch Then
                        $avRet = $avret[1]
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
 
    Return $avRet
 
EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

ok this code get's the title of an application from PID but.....

it get's only 1 title

can someone edit the code so it get's all the titles if there is more than 1 process with the same name ?

ty

That doesn't make sense. If you specify the integer PID, there is at most exactly one process name that matches that PID.

There may be zero to many windows owned by that process -- is that what you meant? If so, you can take the PID, get the process name, then do ProcessList() again on the name to get all instances of that process name in an array. Iterate the array using the PIDs to list all windows of all instances of the process name, and you'll have all windows for that process name.

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

That doesn't make sense. If you specify the integer PID, there is at most exactly one process name that matches that PID.

There may be zero to many windows owned by that process -- is that what you meant? If so, you can take the PID, get the process name, then do ProcessList() again on the name to get all instances of that process name in an array. Iterate the array using the PIDs to list all windows of all instances of the process name, and you'll have all windows for that process name.

;)

He was looping through the pids... well... he was trying to.

I think his main issue was that he was passing the title and not the pid and also was setting the data on a combo incorrectly.

Share this post


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
Sign in to follow this  
Followers 0