Sign in to follow this  
Followers 0
Nicolas971

GUI doesn't want close

5 posts in this topic

#1 ·  Posted (edited)

Hi people,

I have a problem with my script.

In fact, I have 2 functions and they work fine separately. But when I put them together, I have some problems.

My problem :

When I click OK button or when I try to close the window, by clicking on the X button, windows still running and it dosen't close. And it do it for the 2 functions.

Furthermore, after the second GUI function, script stop and it dosen't continue.

So, what I did wrong ? How can I validate (close) the windows by pressing OK button ?

My code is the following :

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)
Opt("GuiOnEventMode", 1)


; --- Déclaration des variables globales ---

;Déclaration des variables pour la fonction "type_install"
Dim $install_type, $val_endloop1, $radio1

;Déclaration des variables pour la fonction "saisie_CBname"
Dim $name, $id_tmp, $val_endloop2


; --- Déclaration des fonctions ---

;Fcontion permettant d'indiquer si la CB dispose d'un acces Internet ou pas
$val_endloop1 = 0
Func type_install()
    Local $msg1, $radio1, $radio2, $btn1
    
    GUICreate("Prérequis d'installation", 400, 275)  

    GUICtrlCreateLabel("Attention, Pour une installation totale, il est impératif de disposer d'une connexion au réseau Internet.", 50, 40, 300, 40, $SS_CENTER)
    
    GUICtrlCreateLabel("Veuillez indiquer ci-après, si la machine dispose d'un accès au réseau Internet ou non :", 50, 80, 300, 40, $SS_CENTER)
    
    $radio1 = GUICtrlCreateRadio("Oui, la Box dispose d'une connxion au réseau Internet.", 25, 140, 350, 20)
    $radio2 = GUICtrlCreateRadio("Non, la Box ne dispose pas de connxeion au réseau Internet.", 25, 180, 360, 20)
    
    GUICtrlSetState($radio2, $GUI_CHECKED)
    
    $btn1 = GUICtrlCreateButton("OK", 175, 230, 50, 20)
    GUICtrlSetOnEvent($btn1, "OkPressed1")
    
    GUISetState()      
    
    ; Run the GUI until the dialog is closed
    While 1
        $msg1 = GUIGetMsg()
        
        If $val_endloop1 = 1 Then ExitLoop
        
        Select
            Case $msg1 = $GUI_EVENT_CLOSE
                Exit
            Case $msg1 = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
                $install_type = 0
            Case $msg1 = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
                $install_type = 1
        EndSelect
    WEnd
EndFunc

Func OkPressed1()
    $val_endloop1 = 1
EndFunc

;Fonction permettant de saisir le nom de la CB
$val_endloop2 = 0
Func saisie_CBname()
    Local $btn, $msg2
    
    GUICreate(" Nom de la Box", 300, 175)
    GUICtrlCreateLabel("Veuillez saisir le nom de la Box.", 20, 20, 250, 30, $SS_CENTER)
    
    $id_tmp = GUICtrlCreateInput("", 100, 60, 100, 20)
    
    $btn = GUICtrlCreateButton("Valider", 112, 120, 75, 20)
    GUICtrlSetOnEvent($btn, "OkPressed2")

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg2 = GUIGetMsg()
        If $msg2 = $GUI_EVENT_CLOSE Then Exit
        If $val_endloop2 = 1 Then ExitLoop
    WEnd
EndFunc

Func OkPressed2()
    $name = GUICtrlRead($id_tmp)
    If $name = "" Then
        MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.")
    ElseIf StringIsSpace($name) Then
        MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.")
    Else
        $val_endloop2 = 1
    EndIf
EndFunc

; --- Appel des fonctions ---

;Choix du type d'installation
type_install()
;Saisie du nom de la Box
saisie_CBname()

PS : Sorry for my english.

Edited by Nicolas971

Share this post


Link to post
Share on other sites



You mix the two GUI concepts: MessageLoop Mode and OnEvent Mode.

Please see the help file: GUI Reference -> GUI Concepts


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Nicolas971,

You were using both OnEvent and GetMessage modes - you shoudl only use one or the other in your script. ;)

Here is the script rewritten in GetMessage mode - with a few other changes for you to spot: :P

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

; --- Déclaration des variables globales ---

;Déclaration des variables Global
Global $install_type, $name

; --- Déclaration des fonctions ---

;Fcontion permettant d'indiquer si la CB dispose d'un acces Internet ou pas
Func type_install()

    Local $hGUI1 = GUICreate("Prérequis d'installation", 400, 275)

    GUICtrlCreateLabel("Attention, Pour une installation totale, il est impératif de disposer d'une connexion au réseau Internet.", 50, 40, 300, 40, $SS_CENTER)

    GUICtrlCreateLabel("Veuillez indiquer ci-après, si la machine dispose d'un accès au réseau Internet ou non :", 50, 80, 300, 40, $SS_CENTER)

    GUIStartgroup()
    Local $radio1 = GUICtrlCreateRadio("Oui, la Box dispose d'une connxion au réseau Internet.", 25, 140, 350, 20)
    Local $radio2 = GUICtrlCreateRadio("Non, la Box ne dispose pas de connxeion au réseau Internet.", 25, 180, 360, 20)
    GUICtrlSetState($radio2, $GUI_CHECKED)

    Local $btn1 = GUICtrlCreateButton("OK", 175, 230, 50, 20)

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btn1
                If GUICtrlRead($radio1) = 1 Then
                    $install_type = 0
                Else
                    $install_type = 1
                EndIf
                GUIDelete($hGUI1)
                ExitLoop
        EndSwitch
    WEnd

EndFunc

;Fonction permettant de saisir le nom de la CB

Func saisie_CBname()

    Local $hGUI2 = GUICreate(" Nom de la Box", 300, 175)
    GUICtrlCreateLabel("Veuillez saisir le nom de la Box.", 20, 20, 250, 30, $SS_CENTER)

    Local $id_tmp = GUICtrlCreateInput("", 100, 60, 100, 20)

    Local $btn = GUICtrlCreateButton("Valider", 112, 120, 75, 20)

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btn
                $name = GUICtrlRead($id_tmp)
                If $name = "" Then
                    MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.")
                ElseIf StringIsSpace($name) Then
                    MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.")
                    GUICtrlSetData($id_tmp, "")
                Else
                    ExitLoop
                EndIf
        EndSwitch
    WEnd

EndFunc

; --- Appel des fonctions ---

;Choix du type d'installation
type_install()
;Saisie du nom de la Box
saisie_CBname()

MsgBox(0, "Resultat", "Type Install = " & $install_type & @CRLF & "CBname = " & $name)

Could I suggest you go and read the first part of the Wiki tutorial "Variables - using Global, Local and ByRef" - you seem a little confused over whether to use Global or Local scope for your variables. As you can see I have only declared 2 variables as Global.

Please ask if you have any questions. :blink:

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

You mix the two GUI concepts: MessageLoop Mode and OnEvent Mode.

Please see the help file: GUI Reference -> GUI Concepts

Ok, thx.

I read it and to test, I just comment the line "Opt("GuiOnEventMode", 1)". Now, I can close my window and exit script correctly.

But of course, the OK button doesn't work. So how can I replace the "GUICtrlSetOnEvent($btn1, "OkPressed1"" ? Because I need an OK button to validate choices/selections.

PS : Sorry I'm new (less 2 weeks experiences with AutoIT), I'm not a dev (just have some base in prog), so it's a little difficult for me :blink:

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi Melba23,

And a big thx :blink:

It works fine. I'm going to read and learn how you did that !

Thx both of you for your contribution.

Edited by Nicolas971

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