Vieri Posted July 1, 2010 Share Posted July 1, 2010 I realize this question may have several answers... Suppose I want to write an autoit script that checks how many windows are open within a specific application. I would want to know the number of children windows opened by a parent main window. I can clearly identify the main parent window with winactivate but I'm not quite sure how to check if there are children windows open (without knowing every single possible "title" strings). An example would be to open Notepad and its "About" message box. How would I write an Autoit script to detect that the parent Notepad window has an open child, WITHOUT knowing the title of the "About" message box? Maybe WinList could do but I'm not quite sure how to "list" only children windows of a main app. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 1, 2010 Moderators Share Posted July 1, 2010 Vieri, This code lists the child windows of Notepad (as you used that as an example). Open Notepad and the About dialog first: ; get some data on the parent $hNotePad_Handle = WinGetHandle("Untitled") $iNotepad_PID = WinGetProcess($hNotePad_Handle) ; List all windows $aWinList = WinList() ; Now go through and see which match the requried PID For $i = 1 To $aWinList[0][0] If WinGetProcess($aWinList[$i][1]) = $iNotepad_PID Then ; But ignore the parent If $aWinList[$i][1] <> $hNotePad_Handle Then ConsoleWrite("Window " & $aWinList[$i][1] & " is a NotePad child" & @CRLF & $aWinList[$i][0] & @CRLF & @CRLF) EndIf EndIf Next I hope it helps you to solve your problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Vieri Posted July 2, 2010 Author Share Posted July 2, 2010 This code lists the child windows of Notepad (as you used that as an example). Open Notepad and the About dialog first: $hNotePad_Handle = WinGetHandle("Untitled") Thanks for the code! It works for Notepad but unfortunately it doesn't work for quite a lot of other apps. For example, open AutoIt Help and run your script. It should not detect any children at all but it does: $hNotePad_Handle = WinGetHandle("AutoIt Help") :-( Link to comment Share on other sites More sharing options...
Vieri Posted July 2, 2010 Author Share Posted July 2, 2010 (edited) Is it OK to pass a handle to WinGetProcess or must it be a Window Title description? [EDIT]: If I run this: ; get some data on the parent $h_Handle = WinGetHandle("AutoIt Help") $i_PID = WinGetProcess($h_Handle) ConsoleWrite("process ID " & $i_PID & @CRLF & @CRLF) ; List all windows $aWinList = WinList() ; Now go through and see which match the requried PID For $i = 1 To $aWinList[0][0] $iPID = WinGetProcess($aWinList[$i][1]) If $iPID = $i_PID Then ; But ignore the parent If $aWinList[$i][1] <> $h_Handle Then ConsoleWrite("Window handle " & $aWinList[$i][1] & " is a child with PID " & $iPID & @CRLF & "Window title: " & $aWinList[$i][0] & @CRLF & @CRLF) EndIf EndIf Next I get this output: process ID 3008 Window handle 0x00040442 is a child with PID 3008 Window title: MCI command handling window Window handle 0x00030420 is a child with PID 3008 Window title: Window handle 0x00020428 is a child with PID 3008 Window title: Window handle 0x00020404 is a child with PID 3008 Window title: Window handle 0x00020448 is a child with PID 3008 Window title: Window handle 0x00020408 is a child with PID 3008 Window title: Edited July 2, 2010 by Vieri Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 2, 2010 Moderators Share Posted July 2, 2010 Vieri,It should not detect any children at all but it doesAnd what makes you think that there are no children? If the PID owns the window, what are they if not children of the process? Remember that Windows creates many windows for a process and not all of them are visible on the screen. So do not be surprised to find that there are rather more than you thought! Is it OK to pass a handle to WinGetProcess or must it be a Window Title description?Read the Help file <Using AutoIt - Window Titles and Text (Advanced)> and you will see the many ways you can use to identify windows - among which you will find this:"When you have a handle you may use it in place of the title parameter in any of the function calls that use the title/text convention."All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Vieri Posted July 2, 2010 Author Share Posted July 2, 2010 Thanks! Just one last question. What is exactly "MCI command handling window" and why is it appearing as a "child" of "AutoIt Help"? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 2, 2010 Moderators Share Posted July 2, 2010 Vieri,More that you ever wanted to know about MCI. Why it appears as a child I have no idea - I presume that every process has one in case it needs to play audio/video files. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Vieri Posted July 4, 2010 Author Share Posted July 4, 2010 Why it appears as a child On another app, autoit reports another child window with the title "Default IME"...I guess I may need to check whether these children windows are actually visible or not.I don't care for invisible windows; I just need to know if a user has opened a secondary window of the same app (which of course is usually "visible").Thanks,Vieri Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 4, 2010 Moderators Share Posted July 4, 2010 Vieri, It gets more complicted the deeper you dig! "By default all windows in a thread share one default IME window. These default IME windows are top-level (popup) windows, and their parent is set to one of the application windows with which they are associated. The default IME window can also have a child window of class MSCTFIME UI."You may well have to use WinGetState to check whether the windows that WinList gives you are visible or not:If BitAnd(WinGetState($hWnd), 2) = 2 Then ConsoleWrite("I am visible" & @CRLF)Do not give up - we are getting there slowly! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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