Jump to content
Sign in to follow this  
Iuli

_ProcessGetWinTitle () UDF

Recommended Posts

Iuli

Hello,

This is my first UDF. I thought it may be useful, because i use it very often in my scripts :)

Code :

;Includes
#include <Process.au3>
#Include <Array.au3>


;===============================================================================
;
; Function Name:    _ProcessGetWinTitle ()
; Description:      Gets all windowss associated with a process in a unidimensional array
; Parameter(s):     $sProcessName - Name of the process ("Explorer.exe", for instance)
;                   $iVisibility - Parameter used to check for visible/invisible windowss
;                   0 - Check only visible windowss
;                   1 - Check for every Window asociated to the specified process
; Requirement(s):   <Process.au3> and <Array.au3> are required
; Return Value(s):  Success : The array containing the windows name
;                   Failure : 0
; Author(s):        Iuli
;===============================================================================
Func _ProcessGetWinTitle($sProcessName,$iVisibility)
    Local $iK, $WinArray[1]
    $aWinList=WinList ()
    For $iK=1 To $aWinList[0][0]
        If $iVisibility=0 Then
            If (_ProcessGetName(WinGetProcess($aWinList[$iK][0]))=$sProcessName) And (_IsVisible($aWinList[$iK][0])) Then
                _ArrayAdd($WinArray,$aWinList[$iK][0])
            EndIf
        ElseIf $iVisibility=1 Then  
            If _ProcessGetName(WinGetProcess($aWinList[$iK][0]))=$sProcessName Then
                _ArrayAdd($WinArray,$aWinList[$iK][0])
            EndIf
        EndIf   
    Next
    Return $WinArray
EndFunc

; ===================================================================================================
; Internal Functions from this point on
; ===================================================================================================
Func _IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Download :

_ProcessGetWinTitle.au3

Enjoy ! Criticism and suggestions are welcomed :lmao: !

Edited by Iuli

[size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent]

Share this post


Link to post
Share on other sites
wraithdu

Here's an alternative that may be faster. It's a polite process close function that sends the WM_CLOSE messsage to all top level windows of a given process. Same basic idea -

Func _CloseProcess_Polite($proc)
    Local $tpid, $array
    $tpid = ProcessExists($proc)
    If $tpid == 0 Then Return
    $array = WinList() ; $array[n][1]=hwnd of all top-level windows
    For $i = 1 To $array[0][0] ; # of windows returned
        ; pid of process that owns window
        If WinGetProcess($array[$i][1]) == $tpid Then ; window is owned by target process
            WinClose($array[$i][1])
        EndIf
    Next
EndFunc
Edited by wraithdu

Share this post


Link to post
Share on other sites
FireFox

$WL = WinList()
For $nb = 1 to $WL[0][0]
$wgp = WinGetProcess($WL[$nb][1])
TrayTip("Window & PID",$WL[$nb][1] & ' = ' & $wgp, 0, 1)
Sleep(250)
Next

if you dont like pid then use _processgetname (udf) or _processlistproperties (udf)

Edit : oops didnt seen script from wraithdu

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

×