zetaimmersion

handling gui closure

10 posts in this topic

#1 ·  Posted

i am creating 1 main gui and using 2 buttons i would like to create a 2'nd gui (which works fine). Is just i cannot close the subsequent gui windows and i don't know why

#include <GUIConstantsEx.au3>

Global $gui_dummy = 9999 ; declare dummy gui variables

main_window_selection ()

Func main_window_selection ()
    $main_GUI = GUICreate("Main Gui", 300, 200)
    Local $add_bttn = GUICtrlCreateButton("Add", 20, 20, 85, 25)
    Local $del_bttn = GUICtrlCreateButton("Delete", 20, 70, 85, 25)
    Local $close_bttn = GUICtrlCreateButton("Close", 210, 170, 85, 25)
    GUISetState()

    While 1
            $get_gui_msg = GUIGetMsg(1)
            Switch $get_gui_msg[1]
                Case $main_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE
                            ExitLoop
                        Case $add_bttn
                            GUICtrlSetState($add_bttn, $GUI_DISABLE) ; disable button wonce pressed
                            add_func ()
                        Case $del_bttn
                            GUICtrlSetState($del_bttn, $GUI_DISABLE)
                            delete_func ()
                        Case $close_bttn
                            ExitLoop
                    EndSwitch
                Case $gui_dummy
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE
                            GUIDelete($gui_dummy)
                            GUICtrlSetState($add_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                            GUICtrlSetState($del_bttn, $GUI_ENABLE)
                    EndSwitch
            EndSwitch
    WEnd
EndFunc

Func delete_func ()
    ; GUI size for the window
    $delete_gui = GUICreate("Deletion GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 30,40)
    $number_delete = GUICtrlCreateInput("", 30, 60, 90)

    $RUN_delete = GUICtrlCreateButton("Delete action", 210, 225)
    $RUN_close = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()
    While 1
         Switch GUIGetMsg()
             Case $GUI_EVENT_CLOSE
                 ExitLoop
             Case $RUN_close
                 ExitLoop
             Case $RUN_delete
                 ; do other fucntions or checks and/or buttons
         EndSwitch
     WEnd

EndFunc

Func add_func ()
    ; GUI size for the window
    $add_gui = GUICreate("Add GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_add = GUICtrlCreateInput("", 130, 160, 90)

    $RUN_add = GUICtrlCreateButton("Delete action", 210, 225)
    $RUN_close = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()
    While 1
         Switch GUIGetMsg()
             Case $GUI_EVENT_CLOSE
                 ExitLoop
             Case $RUN_close
                 ExitLoop
             Case $RUN_add
                 ; do other fucntions or checks and/or buttons
         EndSwitch
     WEnd

EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

zetaimmersion,

Welcome to the AutoIt forums.

You only need one GUIGetMsg loop - like this:

#include <GUIConstantsEx.au3>

Global $add_GUI = 9999, $RUN_close = 9999 ; declare dummy gui variables

main_window_selection ()

Func main_window_selection ()
    $main_GUI = GUICreate("Main Gui", 300, 200)
    Local $add_bttn = GUICtrlCreateButton("Add", 20, 20, 85, 25)
    Local $del_bttn = GUICtrlCreateButton("Delete", 20, 70, 85, 25)
    Local $close_bttn = GUICtrlCreateButton("Close", 210, 170, 85, 25)
    GUICtrlSetState($del_bttn, $GUI_DISABLE)
    GUISetState()

    While 1
            $get_gui_msg = GUIGetMsg(1)
            Switch $get_gui_msg[1]
                Case $main_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_bttn
                            ExitLoop
                        Case $add_bttn
                            GUICtrlSetState($add_bttn, $GUI_DISABLE) ; disable button once pressed
                            GUICtrlSetState($del_bttn, $GUI_ENABLE)
                            add_func ()
                        Case $del_bttn
                            GUIDelete($add_GUI)
                            GUICtrlSetState($add_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                            GUICtrlSetState($del_bttn, $GUI_DISABLE)
                    EndSwitch
                Case $add_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $RUN_close
                            GUIDelete($add_GUI)
                            GUICtrlSetState($add_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                            GUICtrlSetState($del_bttn, $GUI_DISABLE)
                    EndSwitch
            EndSwitch
    WEnd
EndFunc



Func add_func ()
    ; GUI size for the window
    $add_GUI = GUICreate("Add GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_add = GUICtrlCreateInput("", 130, 160, 90)

    $RUN_add = GUICtrlCreateButton("Delete action", 210, 225)
    $RUN_close = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

Please ask if you have any questions about the script.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thank you for having me Melba23

previously i did have it run your way as a v0.1 with only 1 action but in my case i have it expanded to something as follows:

1. main window - separate add button and separate delete button

2. depending which button is selected then 

2.a add - it perform adding to the ActiveDirectory and other scripts with a predefined form and questions

2.b delete - it performs other sets of questions and deletes ActiveDirectory entries and other things

If i can get this working, the modularity of it would allow me to add other automation via another buttons as the script evolves

Share this post


Link to post
Share on other sites

#4 ·  Posted

Think i got something going by changing a few things in the script

Thank you Melba23, this is what i wanted. Appreciate the help.

#include <GUIConstantsEx.au3>

Global $add_GUI = 9999, $RUN_close = 9999 ; declare dummy gui variables

main_window_selection ()

Func main_window_selection ()
    $main_GUI = GUICreate("Main Gui", 300, 200)
    Local $add_bttn = GUICtrlCreateButton("Add", 20, 20, 85, 25)
    Local $del_bttn = GUICtrlCreateButton("Delete", 20, 70, 85, 25)
    Local $close_bttn = GUICtrlCreateButton("Close", 210, 170, 85, 25)
    GUICtrlSetState($del_bttn, $GUI_ENABLE)
    GUISetState()

    While 1
            $get_gui_msg = GUIGetMsg(1)
            Switch $get_gui_msg[1]
                Case $main_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_bttn
                            ExitLoop
                        Case $add_bttn
                            GUICtrlSetState($add_bttn, $GUI_DISABLE) ; disable buttons once 2nd gui is opeed
                            GUICtrlSetState($del_bttn, $GUI_DISABLE)
                            add_func ()
                        Case $del_bttn
                            GUIDelete($add_GUI)
                            GUICtrlSetState($add_bttn, $GUI_DISABLE) ;disable buttons once 2nd gui is opeed
                            GUICtrlSetState($del_bttn, $GUI_DISABLE)
                            delete_func ()
                    EndSwitch
                Case $add_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $RUN_close
                            GUIDelete($add_GUI)
                            GUICtrlSetState($add_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                            GUICtrlSetState($del_bttn, $GUI_ENABLE)
                    EndSwitch
            EndSwitch
    WEnd
EndFunc



Func add_func ()
    ; GUI size for the window
    $add_GUI = GUICreate("Add GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_add = GUICtrlCreateInput("", 130, 160, 90)

    $RUN_add = GUICtrlCreateButton("Delete action", 210, 225)
    $RUN_close = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

Func delete_func ()
    ; GUI size for the window
    $add_GUI = GUICreate("Delete GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_add = GUICtrlCreateInput("", 130, 160, 90)

    $RUN_add = GUICtrlCreateButton("Add action", 210, 225)
    $RUN_close = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

zetaimmersion,

Based on what you actually wanted, I came up with this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $add_GUI = 9999, $del_GUI = 9999
Global $add_add = 9999, $close_add = 9999
Global $del_del = 9999, $close_del = 9999

main_window_selection ()

Func main_window_selection ()
    $main_GUI = GUICreate("Main Gui", 300, 200)
    Local $add_bttn = GUICtrlCreateButton("Add", 20, 20, 85, 25)
    Local $del_bttn = GUICtrlCreateButton("Delete", 20, 70, 85, 25)
    Local $close_bttn = GUICtrlCreateButton("Close", 210, 170, 85, 25)
    GUISetState()

    While 1
            $get_gui_msg = GUIGetMsg(1)
            Switch $get_gui_msg[1]
                Case $main_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_bttn
                            ExitLoop
                        Case $add_bttn
                            GUICtrlSetState($add_bttn, $GUI_DISABLE) ; disable button once pressed
                            add_func ()
                        Case $del_bttn
                            GUICtrlSetState($del_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                            del_func()
                    EndSwitch
                Case $add_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_add
                            GUIDelete($add_GUI)
                            $add_add = 9999
                            $close_add = 9999
                            GUICtrlSetState($add_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                        Case $add_add
                            MsgBox($MB_SYSTEMMODAL, "Adding", "Add action button pressed")
                    EndSwitch
                Case $del_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_del
                            GUIDelete($del_GUI)
                            $del_del = 9999
                            $close_del = 9999
                            GUICtrlSetState($del_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                        Case $del_del
                            MsgBox($MB_SYSTEMMODAL, "Deleting", "Delete action button pressed")
                    EndSwitch
            EndSwitch
    WEnd
EndFunc



Func add_func ()
    ; GUI size for the window
    $add_GUI = GUICreate("Add GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_add = GUICtrlCreateInput("", 130, 160, 90)

    $add_add = GUICtrlCreateButton("Add action", 210, 225)
    $close_add = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

Func del_func ()
    ; GUI size for the window
    $del_GUI = GUICreate("Delete GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_del = GUICtrlCreateInput("", 130, 160, 90)

    $del_del = GUICtrlCreateButton("Delete action", 210, 225)
    $close_del = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

M23

Edit: I see you already have a solution - see how it compares!

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

next beer is on me man!

this is exactly what i wanted. 

Share this post


Link to post
Share on other sites

#7 ·  Posted

zetaimmersion,

Delighted to hear it.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

once I open the 2nd gui and click on the add or delete action button, how do i pipe the input box details to the msg box? previously it was easyer as the ctrlread was in the same place as the current guigetmsg

for example at the Case $add_add how do i read GUICtrlRead($number_add)  from the add_func such that MsgBox($MB_SYSTEMMODAL, "Adding", "Add action button pressed") includes the user's input details from the input box?

Share this post


Link to post
Share on other sites

#9 ·  Posted

for example, the return is 0 and although i know why that is i am not sure how to use GuiCtrlRead to pick up the user input (for at least 1 variable)

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $add_GUI = 9999, $del_GUI = 9999
Global $add_add = 9999, $close_add = 9999
Global $del_del = 9999, $close_del = 9999

main_window_selection ()

Func main_window_selection ()
    $main_GUI = GUICreate("Main Gui", 300, 200)
    Local $add_bttn = GUICtrlCreateButton("Add", 20, 20, 85, 25)
    Local $del_bttn = GUICtrlCreateButton("Delete", 20, 70, 85, 25)
    Local $close_bttn = GUICtrlCreateButton("Close", 210, 170, 85, 25)
    GUISetState()

    While 1
            $get_gui_msg = GUIGetMsg(1)
            Switch $get_gui_msg[1]
                Case $main_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_bttn
                            ExitLoop
                        Case $add_bttn
                            GUICtrlSetState($add_bttn, $GUI_DISABLE) ; disable button once pressed
                            add_func ()
                        Case $del_bttn
                            GUICtrlSetState($del_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                            del_func()
                    EndSwitch
                Case $add_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_add
                            GUIDelete($add_GUI)
                            $add_add = 9999
                            $close_add = 9999
                            GUICtrlSetState($add_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                        Case $add_add
                            Local $number_add = ""
                            MsgBox($MB_SYSTEMMODAL, "Adding", "Display Gui add input  " & GUICtrlRead($number_add))
                    EndSwitch
                Case $del_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_del
                            GUIDelete($del_GUI)
                            $del_del = 9999
                            $close_del = 9999
                            GUICtrlSetState($del_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                        Case $del_del
                            Local $number_del = ""
                            MsgBox($MB_SYSTEMMODAL, "Adding", "Display Gui delete input  " & GUICtrlRead($number_del))
                    EndSwitch
            EndSwitch
    WEnd
EndFunc



Func add_func ()
    ; GUI size for the window
    $add_GUI = GUICreate("Add GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_add = GUICtrlCreateInput("", 130, 160, 90)

    $add_add = GUICtrlCreateButton("Add action", 210, 225)
    $close_add = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

Func del_func ()
    ; GUI size for the window
    $del_GUI = GUICreate("Delete GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_del = GUICtrlCreateInput("", 130, 160, 90)

    $del_del = GUICtrlCreateButton("Delete action", 210, 225)
    $close_del = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

great success! - please close this before i get dumber! ... the final code to get user input looks like this. Hope it helps others. 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $add_GUI = 9999, $del_GUI = 9999
Global $add_add = 9999, $close_add = 9999
Global $del_del = 9999, $close_del = 9999
Global $number_add, $number_del

main_window_selection ()

Func main_window_selection ()
    $main_GUI = GUICreate("Main Gui", 300, 200)
    Local $add_bttn = GUICtrlCreateButton("Add", 20, 20, 85, 25)
    Local $del_bttn = GUICtrlCreateButton("Delete", 20, 70, 85, 25)
    Local $close_bttn = GUICtrlCreateButton("Close", 210, 170, 85, 25)
    GUISetState()

    While 1
            $get_gui_msg = GUIGetMsg(1)
            Switch $get_gui_msg[1]
                Case $main_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_bttn
                            ExitLoop
                        Case $add_bttn
                            GUICtrlSetState($add_bttn, $GUI_DISABLE) ; disable button once pressed
                            add_func ()
                        Case $del_bttn
                            GUICtrlSetState($del_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                            del_func()
                    EndSwitch
                Case $add_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_add
                            GUIDelete($add_GUI)
                            $add_add = 9999
                            $close_add = 9999
                            GUICtrlSetState($add_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                        Case $add_add
                            ;Local $returned_user_add_input = 9999
                            MsgBox($MB_SYSTEMMODAL, "Adding", "Display Gui delete input  " & GUICtrlRead($number_add))
                    EndSwitch
                Case $del_GUI
                    Switch $get_gui_msg[0]
                        Case $GUI_EVENT_CLOSE, $close_del
                            GUIDelete($del_GUI)
                            $del_del = 9999
                            $close_del = 9999
                            GUICtrlSetState($del_bttn, $GUI_ENABLE) ;re-enable buttons once gui2 closed
                        Case $del_del
                            MsgBox($MB_SYSTEMMODAL, "Adding", "Display Gui delete input  " & GUICtrlRead($number_del))
                    EndSwitch
            EndSwitch
    WEnd
EndFunc



Func add_func ()
    ; GUI size for the window
    $add_GUI = GUICreate("Add GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_add = GUICtrlCreateInput("", 130, 160, 90)

    $add_add = GUICtrlCreateButton("Add action", 210, 225)
    $close_add = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()
EndFunc

Func del_func ()
    ; GUI size for the window
    $del_GUI = GUICreate("Delete GUI", 350, 350)

    ;GUICtrlCreateLabel
    GUICtrlCreateLabel ("Input Field 1", 130,140)
    $number_del = GUICtrlCreateInput("", 130, 160, 90)

    $del_del = GUICtrlCreateButton("Delete action", 210, 225)
    $close_del = GUICtrlCreateButton("Close", 230, 320,50)

    GUISetState()

EndFunc

 

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