Sign in to follow this  
Followers 0
Hellsum

Another GUI Switch problem

3 posts in this topic

#1 ·  Posted (edited)

Hello,

as title mention, Ive some problems understanding how GUISwitch() can work properly with my two windowed GUI

After a full day of tryings and after having search for something useful in this forum, here its my problem:

I have a main GUI, with some option used for my script(cutted away from here), the button located at the bottom centre calls a new GUI with the purpose of register the program, but when the second GUI opens, the only thing that works is the Window's "X" button.

I think that issue is about the not correct use of GUISwitch.

Anyone can Help me making work OK and Cancel buttons in the second GUI ?

here is the code of GUI only (no program)

#include <GUIConstants.au3>

Global $CrowdedOpt = False
Global $AutoOpt = False
Global $RunsOpt = 150
Global $LongRunOpt = True
Global $sellbox = 0
Global $RandomOut = 0
Global $right = 0
Global $counter = 0



;-------------------------------
#Region ### START Koda GUI section ### Form=h:\form1.kxf
Global $Main = GUICreate("MainTitle", 322, 239, 321, 190)
;~ GUISetIcon("Monk.ico")
Global $GroupBox1 = GUICtrlCreateGroup("", 8, -4, 305, 201)
Global $Label1 = GUICtrlCreateLabel("Text line 1", 16, 4, 294, 17, $WS_GROUP)
Global $Label2 = GUICtrlCreateLabel("Text line 2", 16, 20, 251, 17, $WS_GROUP)
Global $Label3 = GUICtrlCreateLabel("Text line 3", 16, 36, 156, 17, $WS_GROUP)
Global $Crowded = GUICtrlCreateCheckbox("select 1                         Option", 16, 60, 211, 17)
Global $LongRun = GUICtrlCreateRadio("Long Run", 16, 108, 73, 17)
Global $ShortRun = GUICtrlCreateRadio("Short Run         Option", 96, 108, 133, 17)
Global $AutoOpt = GUICtrlCreateCheckbox("select 2    Option", 16, 84, 215, 17)
Global $RunsNumber = GUICtrlCreateInput("150", 16, 132, 33, 21)
GUICtrlSetLimit(-1, 150)
Global $Label4 = GUICtrlCreateLabel("How Many ? (Max 150 ", 52, 134, 183, 17)
Global $info3 = GUICtrlCreateButton("?", 234, 106, 17, 17, 0)
Global $info1 = GUICtrlCreateButton("?", 234, 58, 17, 17, 0)
Global $info2 = GUICtrlCreateButton("?", 234, 82, 17, 17, 0)
Global $Label5 = GUICtrlCreateLabel("Text line 4", 16, 160, 260, 17)
Global $Label6 = GUICtrlCreateLabel("Text line 5", 16, 178, 193, 17)
Global $Credits = GUICtrlCreateButton("Credits", 266, 36, 37, 15, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Start = GUICtrlCreateButton("&Start", 16, 208, 75, 25)
Global $Register = GUICtrlCreateButton("&Register", 102, 208, 121, 25, 0)
Global $Quit = GUICtrlCreateButton("&Quit", 232, 208, 75, 25)
GUISetState(@SW_SHOW)
$ParentWin_Pos = WinGetPos($Main, "")
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Crowded
            $CrowdedOpt = NOT $CrowdedOpt

        Case $LongRun
            $LongRunOpt = True

        Case $ShortRun
            $LongRunOpt = False

        Case $AutoOpt
            $AutoOpt = NOT $AutoOpt
        Case $Credits
            MsgBox(0,"Credits","Credit text")
        Case $info3
            MsgBox(0,"How Long title","info1")          
        Case $info1
            MsgBox(0,"title2","info2")
        Case $info2
            MsgBox(0,"Auto Option","info3")         
        Case $Label5
        Case $RunsNumber
            If GUICtrlRead($RunsNumber)>150 Or GUICtrlRead($RunsNumber)<1 Then
                    $RunsOpt = 1
                MsgBox(0, "Error", "Please insert a value between 1 and 150")       
                Else
                    $RunsOpt = GUICtrlRead($RunsNumber)
            EndIf
        Case $Start
            If $CrowdedOpt == True Then
                $RandomOut = 6
            Else
                $RandomOut = 7
            EndIf   
            If $AutoOpt == True Then
                $sellbox = 6
            Else
                $sellbox = 7
            EndIf   
            If $LongRunOpt == False Then
                $right= 6
            Else
                $right= 7
            EndIf   
;~          Call("Start")
        Case $Quit
            Exit
;----------------------------------------------         
            
        Case $Register 
            $1msg = 0
            $UpdateProfile = 0
            If $1msg = $UpdateProfile Then
;-
            $ChildWin = GUICreate("Registration", 706,138, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $Main)
            $ActivationEdit = GUICtrlCreateInput("ActivationKey", 8, 76, 233, 21);BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
            $ButtonOk = GUICtrlCreateButton("&OK", 8, 106, 75, 25, 0)
            $ButtonCancel = GUICtrlCreateButton("&Cancel", 95, 106, 75, 25, 0)
            $EnterPassLabel = GUICtrlCreateLabel("Enter Activation Key", 8, 56, 100, 17)
            $Label1 = GUICtrlCreateLabel("Product Key", 8, 6, 65, 17)
            $Input1 = GUICtrlCreateInput("Productkey", 8, 24, 693, 21)
;-
            GUISwitch($ChildWin)
            GUISetState()
            WinActivate("Registration")
            GUISetState(@SW_SHOW)
            While 1
            $msgg = GUIGetMsg()
            If $msgg = $GUI_EVENT_CLOSE Then
            GUIDelete($ChildWin)
            GUISwitch($Main)
            GUISetState()
            WinActivate($Main)
            ExitLoop
            
            Switch $msgg
                case $ButtonCancel
                    MsgBox(0,"omg","gogogogo!")
                If @GUI_WINHANDLE = $ChildWin Then
                GUISetState(@SW_HIDE)
                GUISwitch($Main)
                GUISetState(@SW_ENABLE)
                WinActivate("MainTitle")
                EndIf 
                
            EndSwitch
            EndIf
            WEnd

            EndIf



    EndSwitch
WEnd

Thx in advance

and sorry for my not so good english

Edited by Hellsum

Share this post


Link to post
Share on other sites



Try this:

#include <GUIConstants.au3>

Global $CrowdedOpt = False, $AutoOpt = False, $RunsOpt = 150, $right = 0
Global $LongRunOpt = True, $sellbox = 0, $RandomOut = 0, $counter = 0
Dim $1msg, $UpdateProfile, $ChildWin, $ActivationEdit, $ButtonOk, $ButtonCancel
Dim $EnterPassLabel, $Label1, $Input1, $msgg


;-------------------------------
#Region ### START Koda GUI section ### Form=h:\form1.kxf
Global $Main = GUICreate("MainTitle", 322, 239, 321, 190)
GUISetIcon("Monk.ico")
Global $GroupBox1 = GUICtrlCreateGroup("", 8, -4, 305, 201)
Global $Label1 = GUICtrlCreateLabel("Text line 1", 16, 4, 294, 17, $WS_GROUP)
Global $Label2 = GUICtrlCreateLabel("Text line 2", 16, 20, 251, 17, $WS_GROUP)
Global $Label3 = GUICtrlCreateLabel("Text line 3", 16, 36, 156, 17, $WS_GROUP)
Global $Crowded = GUICtrlCreateCheckbox("select 1                          Option", 16, 60, 211, 17)
Global $LongRun = GUICtrlCreateRadio("Long Run", 16, 108, 73, 17)
Global $ShortRun = GUICtrlCreateRadio("Short Run         Option", 96, 108, 133, 17)
Global $AutoOpt = GUICtrlCreateCheckbox("select 2     Option", 16, 84, 215, 17)
Global $RunsNumber = GUICtrlCreateInput("150", 16, 132, 33, 21)
GUICtrlSetLimit(-1, 150)
Global $Label4 = GUICtrlCreateLabel("How Many ? (Max 150 ", 52, 134, 183, 17)
Global $info3 = GUICtrlCreateButton("?", 234, 106, 17, 17, 0)
Global $info1 = GUICtrlCreateButton("?", 234, 58, 17, 17, 0)
Global $info2 = GUICtrlCreateButton("?", 234, 82, 17, 17, 0)
Global $Label5 = GUICtrlCreateLabel("Text line 4", 16, 160, 260, 17)
Global $Label6 = GUICtrlCreateLabel("Text line 5", 16, 178, 193, 17)
Global $Credits = GUICtrlCreateButton("Credits", 266, 36, 37, 15, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Start = GUICtrlCreateButton("&Start", 16, 208, 75, 25)
Global $Register = GUICtrlCreateButton("&Register", 102, 208, 121, 25, 0)
Global $Quit = GUICtrlCreateButton("&Quit", 232, 208, 75, 25)
GUISetState(@SW_SHOW)
$ParentWin_Pos = WinGetPos($Main, "")
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Crowded
            $CrowdedOpt = Not $CrowdedOpt
            
        Case $LongRun
            $LongRunOpt = True
            
        Case $ShortRun
            $LongRunOpt = False
            
        Case $AutoOpt
            $AutoOpt = Not $AutoOpt
        Case $Credits
            MsgBox(0, "Credits", "Credit text")
        Case $info3
            MsgBox(0, "How Long title", "info1")
        Case $info1
            MsgBox(0, "title2", "info2")
        Case $info2
            MsgBox(0, "Auto Option", "info3")
        Case $Label5
        Case $RunsNumber
            If GUICtrlRead($RunsNumber) > 150 Or GUICtrlRead($RunsNumber) < 1 Then
                $RunsOpt = 1
                MsgBox(0, "Error", "Please insert a value between 1 and 150")
            Else
                $RunsOpt = GUICtrlRead($RunsNumber)
            EndIf
        Case $Start
            If $CrowdedOpt == True Then
                $RandomOut = 6
            Else
                $RandomOut = 7
            EndIf
            If $AutoOpt == True Then
                $sellbox = 6
            Else
                $sellbox = 7
            EndIf
            If $LongRunOpt == False Then
                $right = 6
            Else
                $right = 7
            EndIf
;~             Call("Start")
        Case $Quit
            Exit
            ;----------------------------------------------
        Case $Register
            GUISetState(@SW_HIDE, $Main)
            _register()
    EndSwitch
WEnd

Func _register()
    $1msg = 0
    $UpdateProfile = 0
    If $1msg = $UpdateProfile Then
        ;-
        $ChildWin = GUICreate("Registration", 706, 138, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $Main)
        $ActivationEdit = GUICtrlCreateInput("ActivationKey", 8, 76, 233, 21);BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
        $ButtonOk = GUICtrlCreateButton("&OK", 8, 106, 75, 25, 0)
        $ButtonCancel = GUICtrlCreateButton("&Cancel", 95, 106, 75, 25, 0)
        $EnterPassLabel = GUICtrlCreateLabel("Enter Activation Key", 8, 56, 100, 17)
        $Label1 = GUICtrlCreateLabel("Product Key", 8, 6, 65, 17)
        $Input1 = GUICtrlCreateInput("Productkey", 8, 24, 693, 21)
        ;-
        GUISwitch($ChildWin)
        WinActivate("Registration")
        GUISetState(@SW_SHOW, $ChildWin)
        While 1
            $msgg = GUIGetMsg()
            Select
                case $msgg = $GUI_EVENT_CLOSE or $msgg = $ButtonCancel
                    _cancel()
                    ExitLoop
                Case $msgg = $ButtonOk
                    $GCR = GUICtrlRead($Input1)
                    MsgBox(0, "OK button pressed","Product key:   "&$GCR&@CRLF&"Activation key:   "&$ActivationEdit )
                    _cancel()
                    ExitLoop                    
            EndSelect       
        WEnd
        
    EndIf
EndFunc   ;==>_register

func _cancel()
    GUIDelete($ChildWin)
    GUISwitch($Main)
    GUISetState(@SW_SHOW,$Main)
    WinActivate($Main)
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
Sign in to follow this  
Followers 0