Sign in to follow this  
Followers 0
Synix

Children don't know about their parents

5 posts in this topic

Sorry for that topic title :P I have a question and didn't know a title that suits.

I'm using a function to find all child GUIs of my main GUI and noticed that some wouldn't get captured. On GUIs that have neither the style $WS_POPUP, nor $WS_CHILD set, the "parent" parameter won't do anything.

I thought when passing a valid handle as the parent parameter, this should always work. Here's a quick example:

#include <WinAPI.au3>
#include <WindowsConstants.au3>

$hParent = GUICreate("Parent")
$hChild1 = GUICreate("Child1", 125, 50, -1, -1, -1, -1, $hParent) ;default (-1) includes $WS_POPUP
$hChild2 = GUICreate("Child2", 125, 50, -1, -1, $WS_CHILD, -1, $hParent)
$hChild3 = GUICreate("Child3", 125, 50, -1, -1, 0, -1, $hParent)
$hChild4 = GUICreate("Child4", 125, 50, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU), -1, $hParent)

MsgBox(0, "", _
"Parent of $hChild1: " & _WinAPI_GetParent($hChild1) & @CRLF & _
"Parent of $hChild2: " & _WinAPI_GetParent($hChild2) & @CRLF & _
"Parent of $hChild3: " & _WinAPI_GetParent($hChild3) & @CRLF & _
"Parent of $hChild4: " & _WinAPI_GetParent($hChild4))

I'd understand if you explicitly needed $WS_CHILD as a style for a child window, but since $WS_POPUP also works I am wondering why you can't set the parent for other styled windows. Is this an expected behavior? I couldn't find any information about this.

Share this post


Link to post
Share on other sites



The thing is, I have one main GUI that I want to set as parent for my other GUIs (settings, information window etc.). Using GUISetState() or WinSetState() to hide my main GUI, child windows automatically disappear, but I use a different method.

I use the hide and slide option of _WinAPI_WinAnimate() to "minimize" the main window to tray, but in this case the child GUIs stay visible. To hide visible child GUIs I search for them via WinList() and _WinAPI_GetParent(). Then I hide them manually.

So I noticed that GUIs won't have a parent when missing the $WS_POPUP or $WS_CHILD style. And I just want to understand if this is normal. If so, a remark in the documentation would be nice.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I don't exactly understand because English is not my native language. My example code above was written especially for this thread to show the problem. The code I use would've been too distracting to clearly show the issue.

This uses two of my functions and shows the "problem" especially in my case:

#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

$hParent = GUICreate("Parent", -1, -1, -1, -1, $WS_POPUP)
GUISetState(@SW_SHOW)
$hChild1 = GUICreate("Child1", 150, 50, -1,  @DesktopHeight/2.7, -1, -1, $hParent) ;default (-1) includes $WS_POPUP
GUISetState(@SW_SHOW)
$hChild2 = GUICreate("Child2", 125, 50, 0, 0, BitOR($WS_CHILD, $WS_CAPTION), -1, $hParent)
GUISetState(@SW_SHOW)
$hChild3 = GUICreate("Child3", 125, 50, -1, @DesktopHeight/2.2, 0, -1, $hParent)
GUISetState(@SW_SHOW)
$hChild4 = GUICreate("Child4", 125, 50, -1, @DesktopHeight/1.9, BitOR($WS_CAPTION, $WS_SYSMENU), -1, $hParent)
GUISetState(@SW_SHOW)

Sleep(2500)
$aChildren = _WinListChildWindows($hParent)
_WinArrayHide($aChildren)
_WinAPI_AnimateWindow($hParent, BitOR($AW_HIDE, $AW_SLIDE, $AW_HOR_POSITIVE, $AW_VER_POSITIVE), 200)
MsgBox(0, "", "All child windows successfully hidden.")
Sleep(2500)

Func _WinListChildWindows($hWnd)
    ;returns an array of child windows for the given parent window
    Local $aRet[0][0], $aWinList

    $aWinList = WinList()
    For $i = 1 To UBound($aWinList) - 1
        If $aWinList[$i][1] <> $hWnd And _WinAPI_GetParent($aWinList[$i][1]) = $hWnd Then
            $iPrevSize = UBound($aRet, $UBOUND_ROWS)
            ReDim $aRet[$iPrevSize+1][2]
            $aRet[$iPrevSize][0] = $aWinList[$i][1]
            $aRet[$iPrevSize][1] = _WinAPI_IsWindowVisible($aWinList[$i][1])
        EndIf
    Next

    Return $aRet
EndFunc

Func _WinArrayHide(ByRef $aArray)
    ;hides an array of windows
    If UBound($aArray, $UBOUND_COLUMNS) < 2 Then Return SetError(1)
    For $i = 0 To UBound($aArray) - 1
        If $aArray[$i][1] = 1 Then
            ;fast method [no need for Opt("WinWaitDelay", 0)]
            _WinAPI_ShowWindow($aArray[$i][0], @SW_HIDE)
        EndIf
    Next
EndFunc

As you will see, all child windows get successfully hidden, but child 3 and 4 still show up, since they have no parent, because of the missing style.

So is this now an expected behavior or should the $hParent parameter work regardless of what style the child window has set?

Edited by Synix

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  
Followers 0