【问题标题】:Autoit - Get Window Class by PIDAutoit - 通过 PID 获取窗口类
【发布时间】:2014-11-24 12:52:34
【问题描述】:

我希望 Autoit 在程序上按某个键,但程序窗口没有标题,并且每次启动时都会更改其类。唯一保持一致的是进程名称。

所以我的问题很简单:如何仅使用 PID 获得 Windows 类?

【问题讨论】:

    标签: class autoit pid


    【解决方案1】:

    这有帮助吗?

    #include <Array.au3>
    #include <WinAPI.au3>
    
    Opt("WinDetectHiddenText", 1) ;0=don't detect, 1=do detect
    Opt("WinSearchChildren", 1) ;0=no, 1=search children also
    Opt("WinTextMatchMode", 2) ;1=complete, 2=quick
    Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
    
    
    $a = ProcessGetId('firefox.exe')
    
    For $i = 1 To UBound($a) - 1
        ConsoleWrite(ProcessGetWindow($a[$i]) & @CRLF)
    Next
    
    Func ProcessGetWindow($PId)
        If IsNumber($PId) = 0 Or ProcessExists(ProcessGetName($PId)) = 0 Then
            SetError(1)
        Else
            Local $WinList = WinList()
            Local $i = 1
            Local $WindowTitle = ""
            While $i <= $WinList[0][0] And $WindowTitle = ""
                If WinGetProcess($WinList[$i][0], "") = $PId Then
                    $WindowTitle = $WinList[$i][0]
                Else
                    $i += 1
                EndIf
            WEnd
            Return $WindowTitle
        EndIf
    EndFunc   ;==>ProcessGetWindow
    
    Func ProcessGetId($Process)
        If IsString($Process) = 0 Then
            SetError(2)
        ElseIf ProcessExists($Process) = 0 Then
            SetError(1)
        Else
            Local $PList = ProcessList($Process)
            Local $i
            Local $PId[$PList[0][0] + 1]
            $PId[0] = $PList[0][0]
            For $i = 1 To $PList[0][0]
                $PId[$i] = $PList[$i][1]
            Next
            Return $PId
        EndIf
    EndFunc   ;==>ProcessGetId
    
    Func ProcessGetName($PId)
        If IsNumber($PId) = 0 Then
            SetError(2)
        ElseIf $PId > 9999 Then
            SetError(1)
        Else
            Local $PList = ProcessList()
            Local $i = 1
            Local $ProcessName = ""
    
            While $i <= $PList[0][0] And $ProcessName = ""
                If $PList[$i][1] = $PId Then
                    $ProcessName = $PList[$i][0]
                Else
                    $i = $i + 1
                EndIf
            WEnd
            Return $ProcessName
        EndIf
    EndFunc   ;==>ProcessGetName
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      • 1970-01-01
      • 2011-08-14
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多