Jump to content

Open & Close Paren/Child GUI using GuiOnEventMode


gseller
 Share

Recommended Posts

Sorry, I could not find this or any good example in the helpfile or forum so I just wanted to document it for anyone else looking. So many great scripts coming out in onevent that I am changing some of mine to incorporate new stuff into my existing scripts. Hope this finds someone in need of it... ;)

#include <guiconstants.au3>

Global $hGuiChild

Opt("GuiOnEventMode", 1)
$hGuiParent = GUICreate("Parent GUI", 200, 100, 100, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUISetState()
$ParentLabel = GUICtrlCreateLabel("Parent GUI", 70, 05, 60)
$ClickHereLabel = GUICtrlCreateLabel("Click Here to Launch CHild GUI", 25, 25, 150)
$okbutton = GUICtrlCreateButton("OK", 70, 40, 60)
GUICtrlSetOnEvent($okbutton,"_okbutton")

$CloseMebutton = GUICtrlCreateButton("Close Me", 70, 70, 60)
GUICtrlSetOnEvent($CloseMebutton,"_Quit")

GUISetState()

While 1
    Sleep(20)
WEnd

Func _Quit()
    Exit
EndFunc

Func _okbutton()
$hGuiChild = GUICreate("Child GUI", 200, 100, 300, 300, -1, -1, $hGuiParent)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Warn")
$Closebutton = GUICtrlCreateButton("Close", 70, 50, 60)
GUICtrlSetOnEvent($Closebutton,"_Warn")
 GUISetState(@SW_SHOW)
EndFunc  ;==>ActiverButtonclick

Func _Warn()
    MsgBox(16, "Warning", "You are closing the window.")
    GUIDelete($hGuiChild)
EndFunc
Link to comment
Share on other sites

Nice example. Because you are using Opt("GuiOnEventMode", 1) we can improve what you started by changing _Quit function and use macro @GUI_WinHandle. This will allow you to have multiple child windows and the only thing else to change will be Global $hGuiChild to Global $hGuiParent.

Func _Quit()
    $sTitle = WinGetTitle('')
    MsgBox(16, "Warning", "You are closing the "& $sTitle & ".")    
    If @GUI_WinHandle = $hGuiParent Then
        Exit
    Else        
        GUIDelete(@GUI_WinHandle)
    EndIf
EndFuncoÝ÷ ØLZ^jëh×6#include <guiconstants.au3>

Global $hGuiParent

Opt("GuiOnEventMode", 1)
$hGuiParent = GUICreate("Parent GUI", 200, 100, 100, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUISetState()
$ParentLabel = GUICtrlCreateLabel("Parent GUI", 70, 05, 60)
$ClickHereLabel = GUICtrlCreateLabel("Click Here to Launch CHild GUI", 25, 25, 150)
$okbutton = GUICtrlCreateButton("OK", 70, 40, 60)
GUICtrlSetOnEvent($okbutton, "_okbutton")

$CloseMebutton = GUICtrlCreateButton("Close Me", 70, 70, 60)
GUICtrlSetOnEvent($CloseMebutton, "_Quit")

GUISetState()

While 1
    Sleep(20)
WEnd

Func _Quit()
    $sTitle = WinGetTitle('')
    MsgBox(16, "Warning", "You are closing the "& $sTitle & ".")    
    If @GUI_WinHandle = $hGuiParent Then
        Exit
    Else        
        GUIDelete(@GUI_WinHandle)
    EndIf
EndFunc

Func _okbutton()
    GUICreate("Child GUI", 200, 100, 300, 300, -1, -1, $hGuiParent)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
    $AnotherChildButton = GUICtrlCreateButton('Another Child', 60, 20, 80)
    GUICtrlSetOnEvent($AnotherChildButton, "_anotherchild")
    $Closebutton = GUICtrlCreateButton("Close", 70, 50, 60)
    GUICtrlSetOnEvent($Closebutton, "_Quit")
    GUISetState(@SW_SHOW)
EndFunc   ;==>_okbutton

Func _anotherchild()
    GUICreate("Another Child GUI", 200, 100, 300, 450, -1, -1, $hGuiParent)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
    $Closebutton = GUICtrlCreateButton("Close", 70, 50, 60)
    GUICtrlSetOnEvent($Closebutton, "_Quit")
    GUISetState(@SW_SHOW)
EndFunc
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

  • 3 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...