Delta01 Posted March 27, 2008 Posted March 27, 2008 Well I know there isn't a function called that, but is there a way to get the windows name/handle from the process. I ask because I'm using WinList atm and want to use ProcessList but I have features in my program which renames, resizes windows etc so I need to get the window information in-order to do so.
Paulie Posted March 27, 2008 Posted March 27, 2008 Good ol' thread...http://www.autoitscript.com/forum/index.php?showtopic=39567if it's not exactly the answer you wanted, it will at least give you some keywords to search for.Good luck
Delta01 Posted March 27, 2008 Author Posted March 27, 2008 (edited) Good ol' thread... http://www.autoitscript.com/forum/index.php?showtopic=39567 if it's not exactly the answer you wanted, it will at least give you some keywords to search for. Good luck That sounds like what I need. I'm not very good at analyzing UDF what would I do to get the windows pid? It says it can get it I tried... expandcollapse popupMsgBox(64, "Test", _WinGetInfoByPID("sro_client.exe")) Func _WinGetInfoByPID($sPID) Local $aPList = ProcessList(), $iPID For $iiCount = 1 To $aPList[0][0] If $aPList[$iiCount][1] = $sPID Then If $sPID = 0 Then Return 0 $iPID &= $aPList[$iiCount][1] & Chr(01) EndIf Next $iPID = StringSplit($iPID, Chr(01)) If $iPID = 0 Then Return SetError(1, 0, 0) Local $aStoreHwndAndText[2][9], $nCount = 1 $OptWSC = Opt('WinSearchChildren', 1) $OptWDHT = Opt('WinDetectHiddenText', 1) Local $aWinList = WinList() For $iCount = 1 To $aWinList[0][0] For $xCount = 1 To $iPID[0] If WinGetProcess($aWinList[$iCount][1]) = $iPID[$xCount] And _ $aWinList[$iCount][0] <> '' Then Local $aWinPos = WinGetPos($aWinList[$iCount][1]) Local $aWinClient = WinGetClientSize($aWinList[$iCount][1]) $nCount += 1 ReDim $aStoreHwndAndText[$nCount][9] $aStoreHwndAndText[$nCount - 1][1] = $aWinList[$iCount][0] $aStoreHwndAndText[$nCount - 1][2] = $aWinList[$iCount][1] $aStoreHwndAndText[$nCount - 1][3] = WinGetText($aWinList[$iCount][1]) $aStoreHwndAndText[$nCount - 1][4] = $aWinPos[0] $aStoreHwndAndText[$nCount - 1][5] = $aWinPos[1] $aStoreHwndAndText[$nCount - 1][6] = $aWinClient[0] $aStoreHwndAndText[$nCount - 1][7] = $aWinClient[1] $aStoreHwndAndText[$nCount - 1][8] = WinGetClassList($aWinList[$iCount][1]) EndIf Next Next Opt('WinSearchChildren', $OptWSC) Opt('WinDetectHiddenText', $OptWDHT) If $nCount = 1 Then Return SetError(2, 0, 0) Return $aStoreHwndAndText EndFunc ;==>_WinGetInfoByPID Edited March 27, 2008 by Delta01
Moderators SmOke_N Posted March 27, 2008 Moderators Posted March 27, 2008 expandcollapse popupFunc _WinGetInfoByPID($sPID) Local $aPList, $iPID If $sPID = "" Then $aPList = ProcessList() If $sPID <> "" Then $aPList = ProcessList($sPID) For $iiCount = 1 To $aPList[0][0] If $aPList[$iiCount][1] = $sPID Then If $sPID = 0 Then Return 0 $iPID &= $aPList[$iiCount][1] & Chr(01) EndIf Next $iPID = StringSplit($iPID, Chr(01)) If $iPID = 0 Then Return SetError(1, 0, 0) Local $aStoreHwndAndText[2][9], $nCount = 1 $OptWSC = Opt('WinSearchChildren', 1) $OptWDHT = Opt('WinDetectHiddenText', 1) Local $aWinList = WinList() For $iCount = 1 To $aWinList[0][0] For $xCount = 1 To $iPID[0] If WinGetProcess($aWinList[$iCount][1]) = $iPID[$xCount] And _ $aWinList[$iCount][0] <> '' Then Local $aWinPos = WinGetPos($aWinList[$iCount][1]) Local $aWinClient = WinGetClientSize($aWinList[$iCount][1]) $nCount += 1 ReDim $aStoreHwndAndText[$nCount][9] $aStoreHwndAndText[$nCount - 1][1] = $aWinList[$iCount][0] $aStoreHwndAndText[$nCount - 1][2] = $aWinList[$iCount][1] $aStoreHwndAndText[$nCount - 1][3] = WinGetText($aWinList[$iCount][1]) $aStoreHwndAndText[$nCount - 1][4] = $aWinPos[0] $aStoreHwndAndText[$nCount - 1][5] = $aWinPos[1] $aStoreHwndAndText[$nCount - 1][6] = $aWinClient[0] $aStoreHwndAndText[$nCount - 1][7] = $aWinClient[1] $aStoreHwndAndText[$nCount - 1][8] = WinGetClassList($aWinList[$iCount][1]) EndIf Next Next Opt('WinSearchChildren', $OptWSC) Opt('WinDetectHiddenText', $OptWDHT) If $nCount = 1 Then Return SetError(2, 0, 0) Return $aStoreHwndAndText EndFunc ;==>_WinGetInfoByPIDThe function doesn't return the PID, you can use ProcessExists to get the PID. I changed it to look for the specific exe's PID if you pass a string to it though above. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
PsaltyDS Posted March 27, 2008 Posted March 27, 2008 Well I know there isn't a function called that, but is there a way to get the windows name/handle from the process. I ask because I'm using WinList atm and want to use ProcessList but I have features in my program which renames, resizes windows etc so I need to get the window information in-order to do so. WinGetProcess() returns the PID for a particular window. The opposite of what you want, but it can be used in conjunction with WinList() to search for the window. That leads to a much simpler solution: expandcollapse popup#include <array.au3> ; only for _ArrayDisplay() Global $iSelPID, $avAnswerk, $iErrSav While 1 $iSelPID = InputBox("_ProcessGetWin", "Enter PID to get window info for:") If @error Then Exit $iSelPID = Int($iSelPID) If $iSelPID <> 0 Then $avAnswer = _ProcessGetWin($iSelPID) $iErrSav = @error _ArrayDisplay($avAnswer, "Results, @error = " & $iErrSav) EndIf WEnd ; ------------------------------------------------------- ; Function: _ProcessGetWin ; Purpose: Return information on the Window owned by a process (if any) ; Syntax: _ProcessGetWin($iPID) ; Where: $iPID = integer process ID ; Returns: On success returns an array: ; [0] = Window Title (if any) ; [1] = Window handle ; If $iPID does not exist, returns empty array and @error = 1 ; Notes: Not every process has a window, indicated by an empty array and ; @error = 0, and not every window has a title, so test [1] for the handle ; to see if a window existed for the process. ; Author: PsaltyDS at www.autoitscript.com/forum ; ------------------------------------------------------- Func _ProcessGetWin($iPID) Local $avWinList = WinList(), $avRET[2] For $n = 1 To $avWinList[0][0] If WinGetProcess($avWinList[$n][1]) = $iPID Then $avRET[0] = $avWinList[$n][0] ; Title $avRET[1] = $avWinList[$n][1] ; HWND ExitLoop EndIf Next If $avRET[1] = "" Then SetError(1) Return $avRET EndFunc ;==>_ProcessGetWin Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Delta01 Posted March 28, 2008 Author Posted March 28, 2008 WinGetProcess() returns the PID for a particular window. The opposite of what you want, but it can be used in conjunction with WinList() to search for the window. That leads to a much simpler solution: expandcollapse popup#include <array.au3> ; only for _ArrayDisplay() Global $iSelPID, $avAnswerk, $iErrSav While 1 $iSelPID = InputBox("_ProcessGetWin", "Enter PID to get window info for:") If @error Then Exit $iSelPID = Int($iSelPID) If $iSelPID <> 0 Then $avAnswer = _ProcessGetWin($iSelPID) $iErrSav = @error _ArrayDisplay($avAnswer, "Results, @error = " & $iErrSav) EndIf WEnd ; ------------------------------------------------------- ; Function: _ProcessGetWin ; Purpose: Return information on the Window owned by a process (if any) ; Syntax: _ProcessGetWin($iPID) ; Where: $iPID = integer process ID ; Returns: On success returns an array: ; [0] = Window Title (if any) ; [1] = Window handle ; If $iPID does not exist, returns empty array and @error = 1 ; Notes: Not every process has a window, indicated by an empty array and ; @error = 0, and not every window has a title, so test [1] for the handle ; to see if a window existed for the process. ; Author: PsaltyDS at www.autoitscript.com/forum ; ------------------------------------------------------- Func _ProcessGetWin($iPID) Local $avWinList = WinList(), $avRET[2] For $n = 1 To $avWinList[0][0] If WinGetProcess($avWinList[$n][1]) = $iPID Then $avRET[0] = $avWinList[$n][0] ; Title $avRET[1] = $avWinList[$n][1] ; HWND ExitLoop EndIf Next If $avRET[1] = "" Then SetError(1) Return $avRET EndFunc ;==>_ProcessGetWin Thanks a lot salty. However, I have a process that has two windows (it's for a game, with a bot and then the game window.) how would I get it to return both the games PID and the bot's PID?
PsaltyDS Posted March 28, 2008 Posted March 28, 2008 (edited) Thanks a lot salty. However, I have a process that has two windows (it's for a game, with a bot and then the game window.) how would I get it to return both the games PID and the bot's PID?Well, that depends. Did the one PID spin off two windows? Or did it spawn a child PID for the other window? Either way, you have the tools in front of you to assemble a list. If it's more than one window per PID, then change the loop to make a 2D array of all matches (similar to SmOke_N's post I think) instead of bailing out on the first match. Do the additional windows show up in WinList()? I'm not sure, and they might not.If it's a child process then use something like _ProcessListProperties() to track the chain of child PIDs and get the window of each.That's as much time as I care to spend on bots. Good luck with it... Edited March 28, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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