orbs Posted June 23, 2014 Share Posted June 23, 2014 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. robertocm 1 Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
mpower Posted June 23, 2014 Share Posted June 23, 2014 (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 June 23, 2014 by mpower Link to comment Share on other sites More sharing options...
orbs Posted June 23, 2014 Author Share Posted June 23, 2014 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? Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
mpower Posted June 23, 2014 Share Posted June 23, 2014 (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 expandcollapse popup#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. expandcollapse popup#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 June 23, 2014 by mpower robertocm 1 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 23, 2014 Moderators Share Posted June 23, 2014 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 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
orbs Posted June 24, 2014 Author Share Posted June 24, 2014 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! Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
mpower Posted June 24, 2014 Share Posted June 24, 2014 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: 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