Jump to content

Recommended Posts

Posted

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.

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (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:

Func 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 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.
Posted

Or check It shows how to retrieve the child windows of a process.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • Developers
Posted

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.
  :)

Posted

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.

Posted

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.

Posted

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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...