timmy2 11 Posted November 8, 2012 After opening an MDI program I must wait for the user to click on a drop-down menu in that program. (He's going to select from 4 possible documents to open.) After he makes his selection a child window will open. I won't know its name and really don't care; I just need to maximize this child child window (regardless of which document he opened). Note that there are no other windows open inside this program; just the one child window. Share this post Link to post Share on other sites
water 2,369 Posted November 8, 2012 You could use function WinList to get a list of windows. You need at least some text that is displayed on this window to reduce the number of returned windows. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
jdelaney 313 Posted November 8, 2012 (edited) Get the process id of the parent window, and run this function in a loop...it returns all the window handles of that process, which you can then grab the titles/text/whatever from, and conditionally do certain actions: expandcollapse popupFunc WGe_ProcessGetWindow($p_PID, $p_ReturnBestGuess = False) ; #FUNCTION# ============================================================================================================================ ; Name...........: WGe_ProcessGetWindow ; ; Description ...: Returns an array of HWNDs containing all windows owned by the process $p_PID, or optionally a single "best guess." ; ; Syntax.........: WGe_ProcessGetWindow( $p_PID [, $p_ReturnBestGuess = False ]) ; ; Parameters ....: $p_PID - The PID of the process you want the Window for. ; $p_ReturnBestGuess - If True, function will return only 1 reult on a best-guess basis. ; The "Best Guess" is the VISIBLE window owned by $p_PID with the longest title. ; ; Return values .: Success - Return $_array containing HWND info. ; $_array[0] = Number of results ; $_array[n] = HWND of Window n ; ; Failure - Returns 0 ; ; Error - Returns -1 and sets @error ; 1 - Requires a non-zero number. ; 2 - Process does not exist ; 3 - WinList() Error ; ; Author ........: Andrew Bobulsky, contact: RulerOf <at that public email service provided by Google>. ; Remarks .......: The reverse of WinGetProcess() ; ======================================================================================================================================= Local $p_ReturnVal[1] = [0] Local $p_WinList = WinList() If @error Then ;Some Error handling SetError(3) Return -1 EndIf If $p_PID = 0 Then ;Some Error handling SetError(1) Return -1 EndIf If ProcessExists($p_PID) = 0 Then ;Some Error handling ConsoleWrite("WGe_ProcessGetWindow: Process " & $p_PID & " doesn't exist!" & @CRLF) SetError(2) Return -1 EndIf For $i = 1 To $p_WinList[0][0] Step 1 Local $w_PID = WinGetProcess($p_WinList[$i][1]) ; ConsoleWrite("Processing Window: " & Chr(34) & $p_WinList[$i][0] & Chr(34) & @CRLF & " with HWND: " & $p_WinList[$i][1] & @CRLF & " and PID: " & $w_PID & @CRLF) If $w_PID = $p_PID Then ;ConsoleWrite("Match: HWND " & $p_WinList[$i][1] & @CRLF) $p_ReturnVal[0] += 1 _ArrayAdd($p_ReturnVal, $p_WinList[$i][1]) EndIf Next If $p_ReturnVal[0] > 1 Then If $p_ReturnBestGuess Then Do Local $i_State = WinGetState($p_ReturnVal[2]) Local $i_StateLongest = WinGetState($p_ReturnVal[1]) Select Case BitAND($i_State, 2) And BitAND($i_StateLongest, 2) ;If they're both visible If StringLen(WinGetTitle($p_ReturnVal[2])) > StringLen(WinGetTitle($p_ReturnVal[1])) Then ;And the new one has a longer title _ArrayDelete($p_ReturnVal, 1) ;Delete the "loser" $p_ReturnVal[0] -= 1 ;Decrement counter Else _ArrayDelete($p_ReturnVal, 2) ;Delete the failed challenger $p_ReturnVal[0] -= 1 EndIf Case BitAND($i_State, 2) And Not BitAND($i_StateLongest, 2) ;If the new one's visible and the old one isn't _ArrayDelete($p_ReturnVal, 1) ;Delete the old one $p_ReturnVal[0] -= 1 ;Decrement counter Case Else ;Neither window is visible, let's just keep the first one. _ArrayDelete($p_ReturnVal, 2) $p_ReturnVal[0] -= 1 EndSelect Until $p_ReturnVal[0] = 1 EndIf Return $p_ReturnVal ElseIf $p_ReturnVal[0] = 1 Then Return $p_ReturnVal ;Only 1 window. Else Return 0 ;Window not found. EndIf EndFunc ;==>WGe_ProcessGetWindow Edited November 8, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Share this post Link to post Share on other sites
water 2,369 Posted November 8, 2012 Or check It shows how to retrieve the child windows of a process. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
timmy2 11 Posted November 8, 2012 Universalist, thank you for the help. When I try to Build your code two functions are undefined: ArrayAdd and ArrayDelete. Please advise. Share this post Link to post Share on other sites
Jos 2,175 Posted November 8, 2012 Universalist, thank you for the help. When I try to Build your code two functions are undefined: ArrayAdd and ArrayDelete. Please advise.Dog ate your helpfile? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Share this post Link to post Share on other sites
timmy2 11 Posted November 8, 2012 Thank you for your reply, too, water. I wanted to try Universalist's code first since it appeared ready-to-use, at least for a test. I'm new to AutoIt so I'll need to study up on WinList, and try to understand those other links. Much appreciated, though. Share this post Link to post Share on other sites
timmy2 11 Posted November 8, 2012 Universalist: good one. No, I looked up ArrayAdd but it isn't listed. I looked up "Undefined function" but am too new to AutoIt to determine whether I can ignore such errors or must chase them down. I figured since you gave me the code you might know the error's cause. Share this post Link to post Share on other sites
timmy2 11 Posted November 8, 2012 okay, I figured out that searching in Help requires exact spelling of the search term. And apparently array.au3 is now built in. While those were interesting discoveries that doesn't get me any closer to running Universalist's sample code. Should I assume it's not for running; just for study? Share this post Link to post Share on other sites
stormbreaker 27 Posted November 9, 2012 He's jdelaney, not Universalist. 1 jdelaney reacted to this ---------------------------------------- :bye: Hey there, was I helpful?----------------------------------------My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Share this post Link to post Share on other sites