Показать полную графическую версию : [решено] Можно ли получить список окон, открытых процессом?
Добрый день! Допустим, есть процесс NotePad.exe. Как получить массив из одного элемента, который будет являться хэндлом окна блокнота?
Как получить массив из одного элемента, который будет являться хэндлом окна блокнота? »
А зачем нужен массив?
Вот пример получения хендла окна «Сохранить как» у блокнота:
$iPID = Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)(@WindowsDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@WindowsDir) & "\Notepad.exe")
ProcessWait (http://www.autoitscript.com/autoit3/docs/functions/ProcessWait.htm)("Notepad.exe")
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(500)
Send (http://www.autoitscript.com/autoit3/docs/functions/Send.htm)("^s")
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(1000)
$hSaveAs = _WinGetHandleEx($iPID, "#32770", "", "FolderView")
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, "Result", "hWnd: " & $hSaveAs & ", Title: " & WinGetTitle (http://www.autoitscript.com/autoit3/docs/functions/WinGetTitle.htm)($hSaveAs))
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _WinGetHandleEx($iPID, $sClassNN="", $sPartTitle="", $sText="", $iVisibleOnly=1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) IsString (http://www.autoitscript.com/autoit3/docs/functions/IsString.htm)($iPID) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $iPID = ProcessExists (http://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm)($iPID)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aWList = WinList (http://www.autoitscript.com/autoit3/docs/functions/WinList.htm)("[CLASS:" & $sClassNN & ";REGEXPTITLE:(?i).*" & $sPartTitle & ".*]", $sText)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://www.autoitscript.com/autoit3/docs/functions/SetError.htm)(1, 0, "")
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aWList[0][0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) WinGetProcess (http://www.autoitscript.com/autoit3/docs/functions/WinGetProcess.htm)($aWList[$i][1]) = $iPID Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $iVisibleOnly Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) ($iVisibleOnly And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(WinGetState (http://www.autoitscript.com/autoit3/docs/functions/WinGetState.htm)($aWList[$i][1]), 2)) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $aWList[$i][1]
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://www.autoitscript.com/autoit3/docs/functions/SetError.htm)(2, 0, "")
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Так можно получить список всех окон для процесса.
#Include <Array.au3>
#Include <WinAPIEx.au3>
Global $Data = _WinAPI_EnumProcessWindows(ProcessExists('Notepad.exe'))
If IsArray($Data) Then
_ArrayDisplay($Data)
EndIf
WinAPIEx.au3 (http://autoit-script.ru/index.php/topic,47.0.html)
А зачем нужен массив? »
Некоторые процессы, например IExplore.exe зачастую запускают по несколько окон, поэтому нужен массив.
Так можно получить список всех окон для процесса. »
Спасибо! Ровно то, что надо! :)
Некоторые процессы, например IExplore.exe зачастую запускают по несколько окон, поэтому нужен массив. »
Я это спросил в качестве коментария на цитату:
Как получить массив из одного элемента, который будет являться хэндлом окна блокнота? »
Т.ч совет на будущее - желательно чтобы содержимое темы совпадало с её заголовком ;)
P.S
Тема решена?
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC