我正在寻找一种从进程ID获取窗口标题的方法。
我想构建函数以获取特定窗口的pid并返回其窗口标题。
我尝试使用AutoIt,但是没有用。
任何想法?
这应该很简单:
Process.GetProcessById(processId).MainWindowTitle;
并且,如果您喜欢它作为请求的功能:
public string GetWindowTitle(int processId){
return Process.GetProcessById(processId).MainWindowTitle;
}
以前在AutoIt中已经完成了很多次,可以选择返回属于该进程的所有窗口,而不仅仅是返回主窗口。
This post提供了标准解决方案。如果腐烂蔓延:
;0 will return 1 base array; leaving it 1 will return the first visible window it finds
Func _WinGetByPID($iPID, $nArray = 1)
If IsString($iPID) Then $iPID = ProcessExists($iPID)
Local $aWList = WinList(), $sHold
For $iCC = 1 To $aWList[0][0]
If WinGetProcess($aWList[$iCC][1]) = $iPID And _
BitAND(WinGetState($aWList[$iCC][1]), 2) = 0 Then
If $nArray Then Return $aWList[$iCC][0]
$sHold &= $aWList[$iCC][0] & Chr(1)
EndIf
Next
If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
Return SetError(1, 0, 0)
EndFunc