我希望Autoit按下程序上的某个键,但程序窗口没有标题,每次启动时都会更改其类。唯一保持一致的是流程名称。
所以我的问题很简单:如何仅使用PID来获取Windows类?
答案 0 :(得分:0)
这有帮助吗?
#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