mrmacro

closing GUI the correct way

4 posts in this topic

#1 ·  Posted (edited)

I am slowly modifying my current project as I come across more ways of making this bullet proof, 

I have a Gui thats been generated with the help of Koda and when there is some invalid input the script is set to display a message and then exit

but the Gui and the message box are still BOTH displayed together until the exit statement then they both close

So I have ,I think, got the Gui to close first  then display the messagebox but can you confirm I am doing this correctly

this is the gui form reference

#Region ### START Koda GUI section ### Form=
$Frm_Assist = GUICreate("Assisted Login", 297, 404, 195, 122)

 

this is the code I would like confirmed that is within a case statement 

    Case $Btn_Cancel
                GUIDelete($Frm_Assist)
            MsgBox(0, "Operation has been cancelled", "The Script will now quit.", 2)
            Exit

I don't feel I need to post the whole code as its just this  GUIDelete($Frm_Assist) that I need confirmed

many thanks for the help

Edited by mrmacro

Share this post


Link to post
Share on other sites



#2 ·  Posted

If you ask about GUIDelete() then YES! 
GUIDelete()  for Deletes a GUI window and all controls that it contains.
You can use GUISetState() to hide the GUI

 

Example of GUI (Unrelated):

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

#Region ### START GUI section ### Form=
Global $hGUI = GUICreate("Assisted Login", 326, 62)
GUICtrlCreateLabel("Use Name: ", 8, 8, 60, 17)
Global $iUname = GUICtrlCreateInput("", 80, 8, 145, 21)
GUICtrlCreateLabel("Password: ", 8, 32, 56, 17)
Global $iPassword = GUICtrlCreateInput("", 80, 32, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
Global $bLogin = GUICtrlCreateButton("Button1", 232, 8, 89, 49)
GUISetState(@SW_SHOW)
#EndRegion ### START GUI section ### Form=

Global $uUname, $uPassword

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUISetState(@SW_HIDE)
            Local $iAsk = MsgBox($MB_ICONWARNING + $MB_YESNO, "?", "You want to quit?")
            If $iAsk = 1 Or $iAsk = 6 Then
                MsgBox($MB_ICONWARNING, "Exit", "Operation has been cancelled" & @CRLF & "The Script will now quit.", 2)
                Exit
            EndIf
            GUISetState(@SW_SHOW)
        Case $bLogin
            $uUnam = GUICtrlRead($iUname)
            $uPassword = GUICtrlRead($iPassword)
            MsgBox($MB_ICONINFORMATION, "Login INFO", "Uname: " & $uUnam & @CRLF & "Password: " & $uPassword, 2)
    EndSwitch
WEnd

 


Regards,
 

Share this post


Link to post
Share on other sites

#3 ·  Posted

many thanks

nice to get confirmation i am doing something right , and also get info on doing it another way

also as i understand , if i use GUIDelete($Frm_Assist)  and specifically put the name of the form that is created , then if i were to have as an example 2 different form open at the same time then it would only close the specifically referenced form $Frm_Assist = GUICreate("Assisted Login", 297, 404, 195, 122)

but i am guessing that if i used ' GUIDelete() '  then this would close both i am guessing if they were not rererenced with the form name

i will test this theory later but that is as i would guess it would work

Thanks again

Share this post


Link to post
Share on other sites

#4 ·  Posted

On 14/07/2017 at 10:18 AM, mrmacro said:

many thanks

nice to get confirmation i am doing something right , and also get info on doing it another way

also as i understand , if i use GUIDelete($Frm_Assist)  and specifically put the name of the form that is created , then if i were to have as an example 2 different form open at the same time then it would only close the specifically referenced form $Frm_Assist = GUICreate("Assisted Login", 297, 404, 195, 122)

but i am guessing that if i used ' GUIDelete() '  then this would close both i am guessing if they were not rererenced with the form name

i will test this theory later but that is as i would guess it would work

Thanks again

I tested my theory and it seems that telling the GUIDelete($Frm_Assist)  or the other GUIDelete($Frm_Assist2)  the specific form to delete works by name works but if you just put GUIDelete() then it only deletes one of them

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