Sign in to follow this  
Followers 0
orbs

need explanation about GUI parent/child relationship

7 posts in this topic

i'm kind of struggling trying to understand the concept of GUI parent/child.

what is the difference between just creating a secondary GUI, and creating it as a child of the main GUI? would it behave differently? how?

what are the pros&cons? under what circumstances would i want to use (or avoid) a child GUI rather than an independent GUI?

thanks for any info.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

One explanation is that the child gui will follow the parent gui - e.g. when the parent gui is dragged, the child gui will be dragged with it. It will also not create another window in the taskbar.

Useful when you want to have the flexibility of having multiple guis but without the complexity of having to minimise/move individual guis. i would say it's more for the user experience.

A quick example:

#include <GUIConstants.au3>

Global $iWidth = 800, $iHeight = 600, $bWidth = 100, $bHeight = 30, $cWidth = 300, $cHeight = 150, $mainparentGUI, $childGUI, $parentGUI

$mainparentGUI = GUICreate('Example Main Parent GUI', $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2)
GUISetState()

$childGUI = GUICreate('Example Child GUI', $cWidth, $cHeight, -1, -1, -1, $WS_EX_MDICHILD, $mainparentGUI)
GUISetState()

$parentGUI = GUICreate('Example Parent GUI', $cWidth, $cHeight)
GUISetState()

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $mainparentGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($mainparentGUI)
                    Exit
            EndSwitch
        Case $childGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($childGUI)
            EndSwitch
        Case $parentGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($parentGUI)
            EndSwitch
    EndSwitch
WEnd

There are more benefits but I just cant think of them at the moment

Edited by mpower

Share this post


Link to post
Share on other sites

thank you,

am i correct to understand that if a child GUI is visible, the parent must be also visible? i.e. there can not be a situation where the child is visible but the parent is not?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thank you,

am i correct to understand that if a child GUI is visible, the parent must be also visible? i.e. there can not be a situation where the child is visible but the parent is not?

 

Not necessarily, autoit is quite flexible with the gui, let's expand on my previous example and now add some buttons that hide/show the parent GUI, you can see that it still works :)

#include <GUIConstants.au3>

Global $iWidth = 800, $iHeight = 600, $bWidth = 140, $bHeight = 30, $cWidth = 300, $cHeight = 150, $mainparentGUI, $childGUI, $parentGUI

$mainparentGUI = GUICreate('Example Main Parent GUI', $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2)
$iButton = GUICtrlCreateButton('Hide Main Parent GUI', $iWidth/2 - $bWidth/2, $iHeight/2 - $bHeight/2, $bWidth, $bHeight)
GUISetState()

$childGUI = GUICreate('Example Child GUI', $cWidth, $cHeight, -1, -1, -1, $WS_EX_MDICHILD, $mainparentGUI)
$cButton = GUICtrlCreateButton('Show Main Parent GUI', $cWidth/2 - $bWidth/2, $cHeight/2 - $bHeight/2, $bWidth, $bHeight)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState()

$parentGUI = GUICreate('Example Parent GUI', $cWidth, $cHeight)
GUISetState()

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $mainparentGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($mainparentGUI)
                    Exit
                Case $iButton
                    GUISetState(@SW_HIDE, $mainparentGUI)
                    GUICtrlSetState($cButton, $GUI_SHOW)
            EndSwitch
        Case $childGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($childGUI)
                Case $cButton
                    GUISetState(@SW_SHOW, $mainparentGUI)
                    GUICtrlSetState($cButton, $GUI_HIDE)
            EndSwitch
        Case $parentGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($parentGUI)
            EndSwitch
    EndSwitch
WEnd

A more interesting example and use of Parent/Child GUI is the ability to Lock the parent GUI whilst the Child GUI is active. Note how if you show the child GUI and then click anywhere on the parent GUI the Child GUI will *flash*. This is useful where you don't want a user to dismiss something important... i.e some action needs to be done (e.g. press a button) on the child GUI before the parent GUI is activated again.

#include <GUIConstants.au3>

Global $iWidth = 800, $iHeight = 600, $bWidth = 200, $bHeight = 30, $cWidth = 300, $cHeight = 150, $mainparentGUI, $childGUI, $parentGUI

$mainparentGUI = GUICreate('Example Main Parent GUI', $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2)
$iButton = GUICtrlCreateButton('Show Child GUI and Lock Parent GUI', $iWidth/2 - $bWidth/2, $iHeight/2 - $bHeight/2, $bWidth, $bHeight)
GUISetState()

$childGUI = GUICreate('Example Child GUI', $cWidth, $cHeight, -1, -1, -1, $WS_EX_MDICHILD, $mainparentGUI)
$cButton = GUICtrlCreateButton('Hide Child GUI and Unlock Parent GUI', $cWidth/2 - $bWidth/2, $cHeight/2 - $bHeight/2, $bWidth, $bHeight)

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $mainparentGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($mainparentGUI)
                    Exit
                Case $iButton
                    GUISetState(@SW_DISABLE, $mainparentGUI)
                    GUISetState(@SW_SHOW, $childGUI)
            EndSwitch
        Case $childGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($childGUI)
                Case $cButton
                    GUISetState(@SW_ENABLE, $mainparentGUI)
                    GUISetState(@SW_HIDE, $childGUI)
            EndSwitch
        Case $parentGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($parentGUI)
            EndSwitch
    EndSwitch
WEnd
Edited by mpower

Share this post


Link to post
Share on other sites

I always direct people to the Wiki article when confronting the parent/child relationship. It is mainly about the how of doing it, but by going through it I think you can glean the relationship between multiple GUIs as well.

http://www.autoitscript.com/wiki/Managing_Multiple_GUIs


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

i think the feature i will make most use of is the disabled parent while a child is in use for important message or configuration interface - to prevent confusion when users switch focus to the parent when they should work with the child.

thanks for all the help!

Share this post


Link to post
Share on other sites

I also think that's one of the more important features of the parent/child gui relationship and it's something I'm actually having trouble with when using $WS_POPUP as a style on the parent and child GUIs.

I've actually been trying to find a workaround but yet to succeed in re-creating a similar style child gui *flashing* when trying to click on the parent gui (when both guis are $WS_POPUP)

My issue is explained here: 

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