Bitte testen... _PIdGetWindow

  • Hallo Leute,

    Das ist sozusagen der 1. Versuch einer Sinnvollen UDF. Bitte teilt mir eure Meinungen und ERfahrungen mit, auch wenn Sie nicht so schön sind... ^^

    Danke an alle...

    Hier die Func:

    Spoiler anzeigen
    [autoit]


    ;============================================================================================
    ;
    ; Function Name: _PIdGetWindow
    ; Description: Returns the Windowhandle(s) owned by the specified process (PId only !).
    ;
    ; Parameter(s): $iPid - the owner-PID.
    ;
    ; $iWndState - WindowState´s (default = active Windows) Option´s as shown
    ; by Helpfile for WinGetState()
    ;
    ; $iOption - Optional : return/search methods :
    ; 0 - returns Processname for the window declared at $iWndState.
    ; 1 - returns new PID for the Process.
    ; 2 - returns WindowTitle for matches in $iWndState(default).
    ; 3 - returns WindowHandle for matches in $iWndState.
    ; 4 - returns WindowState for specified PId.
    ; 5 - returns an Array with all Data can found for Processes and Windows.
    ;
    ;
    ; Return Value(s): On Success - returns an Array (see below for $iOption method 5).
    ; $array[0][0] - number of Processes
    ; $array[x][0] - Processname
    ; $array[x][1] - ProcessId (if Process already exists, a new PId is given by this function)
    ; $array[x][2] - WindowTitle
    ; $array[x][3] - Windowhandle
    ; $array[x][4] - Windowstate
    ;
    ; On Failure - returns 0 and sets @error to 1.
    ;
    ; Note´s: For this Function, <Array.au3> & <Process.au3> must be included.
    ;
    ; Author(s): Stinger2K
    ;
    ;============================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func _PIdGetWindow($iPId, $iWndState = 2, $iOption = 2)
    Local $aResult[1]
    Local $var = _ProcessGetName($iPId)
    Local $test = ProcessExists($var)
    Local $handle_name = WinList()
    If $test <> $iPId Then ; make sure that process exits once
    ProcessClose($var)
    Sleep(1000)
    EndIf
    ProcessWait($var)
    For $i = 1 To $handle_name[0][0]
    ReDim $aResult[UBound($aResult) + 1][5]
    $aResult[UBound($aResult) - 1][0] = _ProcessGetName(WinGetProcess($handle_name[$i][1]))
    $aResult[UBound($aResult) - 1][1] = WinGetProcess($handle_name[$i][1])
    $aResult[UBound($aResult) - 1][2] = $handle_name[$i][0]
    $aResult[UBound($aResult) - 1][3] = $handle_name[$i][1]
    $aResult[UBound($aResult) - 1][4] = WinGetState($handle_name[$i][1])
    If $aResult[$i][1] = $iPId And BitAND(WinGetState($aResult[$i][3]), $iWndState) Then
    If $iOption = 0 Then
    Return $aResult[$i][0] ; Processname
    ElseIf $iOption = 1 Then
    Return $aResult[$i][1] ; new PID
    ElseIf $iOption = 2 Then
    Return $aResult[$i][2] ; WindowTitle
    ElseIf $iOption = 3 Then
    Return $aResult[$i][3] ; Windowhandle
    ElseIf $iOption = 4 Then
    Return $aResult[$i][4] ; Windowstate
    EndIf
    Else
    EndIf
    Next
    If $iOption = 5 Then
    _ArraySort($aResult)
    Return $aResult
    EndIf
    If $iOption > 5 Or $iOption < 0 Then
    Return -2
    EndIf
    SetError(1)
    Return -1
    EndFunc ;==>_PIdGetWindow

    [/autoit]
    Spoiler anzeigen
    Zitat

    Ich weiß wo dein Haus wohnt... 8o

    2 Mal editiert, zuletzt von stinger2k (16. Mai 2010 um 20:28)

  • Das hatten wir erst gestern besprochen... ^^

    Weil bei bestimmten Programmen es vorkommt das sie zwar mit einer neuen PId starten, jedoch den gestarteten Prozess gleich wieder killen und nur ein neues Fenster unter der selben PId starten (Outlook, Explorer, etc...)

    Spoiler anzeigen
    Zitat

    Ich weiß wo dein Haus wohnt... 8o

  • Sinnvoll ist es wenn man aus der Registry Standardprogramme ausliest (z.B. _INetMail () macht das um den Standard-Mail-Client zu starten...).

    z.B.: möchte ich warten bis ein Fenster existiert (wobei ich den Titel oder Text des Fensters nicht wissen kann), um dann per Send("^v") eine Dateianlage zu übergeben.


    Bei mir funktioniert die Func nur dann einwandfrei, wenn die übergebene PID stimmt, was jedoch nicht der Fall ist wenn z.B. Outlook schon in einer Instanz offen ist... Dadurch wird auch kein passender Fensterhandle gefunden da die PID die mir bei Run() übergeben wird nicht existiert( kannst du probieren indem du die PId´s im Taskmanager vergleichst...)


    mit ProcessClose() möchte ich nur sicherstellen das keine Instanz mehr offen ist wenn das Programm startet - damit ich die richtige PId bekomme.


    PS: Danke, für deine Statement´s...

    Spoiler anzeigen
    Zitat

    Ich weiß wo dein Haus wohnt... 8o

  • schön

    Er weitere es doch um einen process manager ,in einer listview
    über welche man per button den titel bekommt

    Mfg.Simon