Sign in to follow this  
Followers 0
Geert

Close Childgui Without Script Termination

8 posts in this topic

I am trying to use a childgui. Normally when closing the childgui $GUI_EVENT_CLOSE is given and will end the script. I would like the script end only when then parentgui is being closed.

So I used WinActive($ChildGui) to make it work.

Is this the right way to do this or is there an alternative.

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced

$ParentGUI = GUICreate("Parent") ; will create a dialog box that when displayed is centered
$ButtonOpenChildGUI = GUICtrlCreateButton("Open ChildGUI", 10, 30, 100)
$Input = GUICtrlCreateInput("", 160, 65, 130, 20)

$ChildGui = GUICreate("Child", 200, 200, 600, 300, -1, -1, $ParentGUI) ; will create a dialog box
$ButtonTime = GUICtrlCreateButton("Time", 10, 30, 50)

GUISetState(@SW_SHOW, $ParentGUI)     ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            If WinActive($ChildGui) Then
                GUISetState(@SW_HIDE, $ChildGui); Hide $ChildGui
            Else
                ExitLoop;   Exit Program
            EndIf
        Case $msg = $ButtonOpenChildGUI
            GUISetState(@SW_SHOW, $ChildGui)
        Case $msg = $ButtonTime
            GUICtrlSetData($Input, @HOUR & @MIN & @SEC)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



I would have each in its own loop

i.e.

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4)   ;1=start, 2=subStr, 3=exact, 4=advanced

$ParentGUI = GUICreate("Parent"); will create a dialog box that when displayed is centered
$ButtonOpenChildGUI = GUICtrlCreateButton("Open ChildGUI", 10, 30, 100)
$Input = GUICtrlCreateInput("", 160, 65, 130, 20)

GUISetState(@SW_SHOW, $ParentGUI)    ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
 $msg = GUIGetMsg()
 Select
  Case $msg = $GUI_EVENT_CLOSE
   ExitLoop;    Exit Program
  Case $msg = $ButtonOpenChildGUI
   _ChildGui()
 EndSelect
WEnd


Func _ChildGui()
; Run the GUI until the dialog is closed
 $ChildGui = GUICreate("Child", 200, 200, 600, 300, -1, -1, $ParentGUI); will create a dialog box
 $ButtonTime = GUICtrlCreateButton("Time", 10, 30, 50)
 GUISetState(@SW_SHOW, $ChildGui)    ; will display an empty dialog box
 While 1
  $msg2 = GUIGetMsg()
  Select
   Case $msg2 = $GUI_EVENT_CLOSE
    ExitLoop;   Exit Program
   Case $msg2 = $ButtonTime
    GUICtrlSetData($Input, @HOUR & @MIN & @SEC)
  EndSelect
 WEnd
 GUIDelete($ChildGui)
EndFunc  ;==>_ChildGui

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well this is looking better. Calling the childGUI as a function gives more order in the script.

But: when the childGUI is open and then you close the parentGUI, it closes childGUI instead of exiting te script...

Edited by Geert

Share this post


Link to post
Share on other sites

Well this is looking better. Calling the childGUI as a function gives more order in the script.

But: when the childGUI is open and then you close the parentGUI, it closes childGUI instead of exiting te script...

just change the exitloop in the main loop to exit


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Or...

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4)  ;1=start, 2=subStr, 3=exact, 4=advanced

$ParentGUI = GUICreate("Parent"); will create a dialog box that when displayed is centered
$ButtonOpenChildGUI = GUICtrlCreateButton("Open ChildGUI", 10, 30, 100)
$Input = GUICtrlCreateInput("", 160, 65, 130, 20)

GUISetState(@SW_SHOW, $ParentGUI)   ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   ExitLoop;    Exit Program
  Case $msg = $ButtonOpenChildGUI
  ;typically we disable the parent while the child is open
  ;GUISetState(@SW_DISABLE, $ParentGUI)
   _ChildGui($ParentGUI)
  ;GUISetState(@SW_ENABLE, $ParentGUI)
EndSelect
WEnd


Func _ChildGui($sParent)
; Run the GUI until the dialog is closed
$ChildGui = GUICreate("Child", 200, 200, 600, 300, -1, -1, $ParentGUI); will create a dialog box
$ButtonTime = GUICtrlCreateButton("Time", 10, 30, 50)
GUISetState(@SW_SHOW, $ChildGui)    ; will display an empty dialog box
While 1
  $msg2 = GUIGetMsg()
  Select
   Case $msg2 = $GUI_EVENT_CLOSE And WinActive($sParent)
    Exit
   Case $msg2 = $GUI_EVENT_CLOSE
    ExitLoop;   Exit Program
   Case $msg2 = $ButtonTime
    GUICtrlSetData($Input, @HOUR & @MIN & @SEC)
  EndSelect
WEnd
GUIDelete($ChildGui)
EndFunc ;==>_ChildGui


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

just change the exitloop in the main loop to exit

I tried that already, it's not doing what is should do...

Share this post


Link to post
Share on other sites

or make it a modal child

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4)   ;1=start, 2=subStr, 3=exact, 4=advanced

$ParentGUI = GUICreate("Parent"); will create a dialog box that when displayed is centered
$ButtonOpenChildGUI = GUICtrlCreateButton("Open ChildGUI", 10, 30, 100)
$Input = GUICtrlCreateInput("", 160, 65, 130, 20)

GUISetState(@SW_SHOW, $ParentGUI)    ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
 $msg = GUIGetMsg()
 Select
  Case $msg = $GUI_EVENT_CLOSE
   Exit;    Exit Program
  Case $msg = $ButtonOpenChildGUI
   GUISetState(@SW_DISABLE, $ParentGUI)
   _ChildGui()
 EndSelect
WEnd


Func _ChildGui()
; Run the GUI until the dialog is closed
 $ChildGui = GUICreate("Child", 200, 200, 600, 300, -1, -1, $ParentGUI); will create a dialog box
 $ButtonTime = GUICtrlCreateButton("Time", 10, 30, 50)
 GUISetState(@SW_SHOW, $ChildGui)    ; will display an empty dialog box
 While 1
  $msg2 = GUIGetMsg()
  Select
   Case $msg2 = $GUI_EVENT_CLOSE
    ExitLoop;   Exit Program
   Case $msg2 = $ButtonTime
    GUICtrlSetData($Input, @HOUR & @MIN & @SEC)
  EndSelect
 WEnd
 GUISetState(@SW_ENABLE, $ParentGUI)
 GUISwitch($ParentGUI)
 GUIDelete($ChildGui)
EndFunc  ;==>_ChildGui

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Thank you both!

My script wil use SmOke_N's: $msg2 = $GUI_EVENT_CLOSE And WinActive($sParent) to keep control on the parentGUI

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