Jump to content
Sign in to follow this  
Vieri

how to make sure only one window of a specific app is open

Recommended Posts

Vieri

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

Share this post


Link to post
Share on other sites
Melba23

Vieri,

This code lists the child windows of Notepad (as you used that as an example). Open Notepad and the About dialog first: :mellow:

; 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. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Vieri

This code lists the child windows of Notepad (as you used that as an example). Open Notepad and the About dialog first: :blink:

$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")

:-(

Share this post


Link to post
Share on other sites
Vieri

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 by Vieri

Share this post


Link to post
Share on other sites
Melba23

Vieri,

It should not detect any children at all but it does

And what makes you think that there are no children? :P 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? :blink:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Vieri

Thanks!

Just one last question. What is exactly "MCI command handling window" and why is it appearing as a "child" of "AutoIt Help"?

Share this post


Link to post
Share on other sites
Melba23

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Vieri

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

Share this post


Link to post
Share on other sites
Melba23

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! :blink:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×