BruceCopperField Posted December 22, 2009 Posted December 22, 2009 I know currently Autoit is using the title text to identify a window. However, my script could be run on Windows of various languages and I cannot foresee the title text in advance since there will be some language I do not understand. I would like to use process Id to get the Window but isn't sure how to. I know the process Id of my target Window which is spawn by my process. Then I just use WinList() to enumerate all and select those with the desired pid: enumProcesWindows(2046, $allHWND) Func enumProcessWindows(Const $pid, ByRef $allHWND) Local $winList=WinList() For $i = 1 To $winList[0][0] If WinGetProcess($winList[$i][1]) = $pid Then _ArrayAdd($allHWND, $winList[$i][1]) EndIf Next EndFunc My $allHWND array would contains all the controls belonging to my pid. But the problem is, the array contains handle to my target Window as well as its child controls. How could I tell which one is a control of my window which one is my window's handle?
picea892 Posted December 22, 2009 Posted December 22, 2009 Seems you need to examine all top level windows. From there you can query the process id. I will give two solutions. The first uses a winapi command to get top level windows, the second has a couple examples,lists all taskbar windows or an exclusion list. 1) _WinAPI_EnumWindowsTop 2) http://www.autoitscript.com/forum/index.php?showtopic=104829&st=0&p=741551&hl=list%20taskbar%20windows&fromsearch=1&#entry741551
SEuBo Posted December 22, 2009 Posted December 22, 2009 (edited) Func _WinActivateByProcessName($sProcessName,$iAll=0) ;Oscar (www.autoit.de) Local $aProcessList, $aWinList $aProcessList = ProcessList($sProcessName) If @error Then Return $aWinList = WinList() If $aWinList[0][0] = 0 Then Return For $i = 1 To $aWinList[0][0] For $j = 1 To $aProcessList[0][0] If WinGetProcess($aWinList[$i][1]) = $aProcessList[$j][1] Then WinActivate($aWinList[$i][1]) If $iAll = 0 Then Return EndIf Next Next EndFunc /EDIT: Oops, my fault! I read "ProcessName" instead of "PID" :S Edited December 22, 2009 by SEuBo AutoIt Examples/UDF's:Generate Function at Runtime using IRunningObjectTable / AutoItObjectVery Simple Inter-Process Communication (using AutoItObject Pure AutoIt)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now