Jump to content

2 GUI windows...buttons not working


beanwi
 Share

Recommended Posts

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

Link to comment
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")
Link to comment
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")
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
Link to comment
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

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...