Sign in to follow this  
Followers 0
beanwi

2 GUI windows...buttons not working

6 posts in this topic

Me and my friend are attempting to create a text based game using autoit

this is the script we have so far.....

CODE
;GUI Interface Include File

#include <WindowsConstants.au3>

;Creating GUI and Styles

GUICreate ("TIMMY", 400, 400)

GUISetState ()

GUISetStyle ($WS_Caption)

;Creating GUI Buttons

$HelpButton = GUICtrlCreateButton ( "HELP FILE", 1, 1, 60, 20)

$ExitButton = GUICtrlCreateButton ( "Exit", 61, 1, 60, 20)

;Setting Button Parameters

While 1

$Msg = GUIGetMsg()

Select

Case $Msg = $HelpButton

GUICreate ("2ndwindow", 200, 200)

GUISetState()

GUISetStyle ($WS_Caption)

$HelpExitButton = GUICtrlCreateButton ( "Exit", 1, 1, 60, 20)

While 1

$Msg2 = GUIGetMsg()

Select

Case $Msg2 = $HelpExitButton

GUIDelete ()

EndSelect

WEnd

Case $Msg = $ExitButton

ExitLoop

EndSelect

WEnd

;Closing Statement

MsgBox (0,"Thank You", "Thank you for playing")

the problem is that when the GUI first opens both buttons work, but then when the 2nd GUI window opens and you close it the buttons no longer work...

if anyone could help that would be great

Share this post


Link to post
Share on other sites



This is what we like to call an endless loop! You must exit the While loop after you delete the gui.

#include <WindowsConstants.au3>

;Creating GUI and Styles
GUICreate ("TIMMY", 400, 400)
GUISetState ()
GUISetStyle ($WS_Caption)

;Creating GUI Buttons
$HelpButton = GUICtrlCreateButton ( "HELP FILE", 1, 1, 60, 20)
$ExitButton = GUICtrlCreateButton ( "Exit", 61, 1, 60, 20)

;Setting Button Parameters
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $HelpButton
            GUICreate ("2ndwindow", 200, 200)
            GUISetState()
            GUISetStyle ($WS_Caption)
            $HelpExitButton = GUICtrlCreateButton ( "Exit", 1, 1, 60, 20)
            While 1
                $Msg2 = GUIGetMsg()
                Select
                    Case $Msg2 = $HelpExitButton
                        GUIDelete ()
                        ExitLoop
                EndSelect
            WEnd
        Case $Msg = $ExitButton
        ExitLoop
    EndSelect
WEnd

;Closing Statement
MsgBox (0,"Thank You", "Thank you for playing")

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This is what we like to call an endless loop! You must exit the While loop after you delete the gui.

#include <WindowsConstants.au3>

;Creating GUI and Styles
GUICreate ("TIMMY", 400, 400)
GUISetState ()
GUISetStyle ($WS_Caption)

;Creating GUI Buttons
$HelpButton = GUICtrlCreateButton ( "HELP FILE", 1, 1, 60, 20)
$ExitButton = GUICtrlCreateButton ( "Exit", 61, 1, 60, 20)

;Setting Button Parameters
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $HelpButton
            GUICreate ("2ndwindow", 200, 200)
            GUISetState()
            GUISetStyle ($WS_Caption)
            $HelpExitButton = GUICtrlCreateButton ( "Exit", 1, 1, 60, 20)
            While 1
                $Msg2 = GUIGetMsg()
                Select
                    Case $Msg2 = $HelpExitButton
                        GUIDelete ()
                        ExitLoop
                EndSelect
            WEnd
        Case $Msg = $ExitButton
        ExitLoop
    EndSelect
WEnd

;Closing Statement
MsgBox (0,"Thank You", "Thank you for playing")
the reason i wanted an endless loop is because i wanted it to loop the cases until i pressed the exit button, because theres an exit loop command in the $exitbutton variable, so i want the original GUI window to stay up after i close the help window Edited by beanwi

Share this post


Link to post
Share on other sites

This is how I do it!!!

#include <WindowsConstants.au3>

;Creating GUI and Styles
$GUI_1 = GUICreate("TIMMY", 400, 400)
GUISetStyle($WS_Caption)
$HelpButton = GUICtrlCreateButton("HELP FILE", 1, 1, 60, 20)
$ExitButton = GUICtrlCreateButton("Exit", 61, 1, 60, 20)
GUISetState()

; GUI #2
$GUI_2 = GUICreate("2ndwindow", 200, 200)
GUISetStyle($WS_Caption)
$HelpExitButton = GUICtrlCreateButton("Exit", 1, 1, 60, 20)
GUISetState(@SW_HIDE, $GUI_2)

;Setting Button Parameters
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $HelpButton
            GUISetState(@SW_SHOW, $GUI_2)
        Case $Msg = $HelpExitButton
            GUISetState(@SW_HIDE, $GUI_2)
        Case $Msg = $ExitButton
            ExitLoop
    EndSelect
WEnd

;Closing Statement
MsgBox(0, "Thank You", "Thank you for playing")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

This is how I do it!!!

#include <WindowsConstants.au3>

;Creating GUI and Styles
$GUI_1 = GUICreate("TIMMY", 400, 400)
GUISetStyle($WS_Caption)
$HelpButton = GUICtrlCreateButton("HELP FILE", 1, 1, 60, 20)
$ExitButton = GUICtrlCreateButton("Exit", 61, 1, 60, 20)
GUISetState()

; GUI #2
$GUI_2 = GUICreate("2ndwindow", 200, 200)
GUISetStyle($WS_Caption)
$HelpExitButton = GUICtrlCreateButton("Exit", 1, 1, 60, 20)
GUISetState(@SW_HIDE, $GUI_2)

;Setting Button Parameters
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $HelpButton
            GUISetState(@SW_SHOW, $GUI_2)
        Case $Msg = $HelpExitButton
            GUISetState(@SW_HIDE, $GUI_2)
        Case $Msg = $ExitButton
            ExitLoop
    EndSelect
WEnd

;Closing Statement
MsgBox(0, "Thank You", "Thank you for playing")

8)

thanks for the help, i didnt even think about hiding it

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

thanks for the help, i didnt even think about hiding it

Well, I commend your "thinking" for your first post/thread

... Welcome to the Autoit Forums!!!

8)

Edited by Valuater

NEWHeader1.png

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