Jump to content

GUI Window closes...


Recommended Posts

My code uses function calls within the GUI to bounce through various commands, but after a string of commands reaches the point where they complete and I would think I would be sent back to my original window, all of my windows close. Here is the piece of script controlled the GUI I want to keep open until closed

#Region ;Text Client
$outputtext = $MOTD
$TextClient = GUICreate("RPG Bot", 625, 443, 225, 248, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_VSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS))
GUISetBkColor(0x000000)
$input = GUICtrlCreateInput("", 0, 420, 601, 23, $WS_BORDER)
GUICtrlSetFont(-1, 8, 400, 0, "Fixedsys")
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$output = GUICtrlCreateLabel($outputtext, 5, 5, 600, 395)
GUICtrlSetFont(-1, 8, 400, 0, "Fixedsys")
GUICtrlSetColor(-1, 0xC8C8C8)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKHCENTER+$GUI_DOCKVCENTER)
GUISetState(@SW_SHOW)
#EndRegion ;Text Client

$outputtext = $outputtext & @CRLF & "Would you like to start a new game? Y/N" & @CRLF
GUICtrlSetData($output,$outputtext)

While 1
$TCMsg = GUIGetMsg()
Select
    Case $TCMsg = $GUI_EVENT_CLOSE
;~      Quit()
        Exit ; Remove the straight exit and add a quit function
    Case $TCMsg = $input
        $line = GUICtrlRead($input)
        $outputtext = $outputtext & @CRLF & "DoubleMcLovin: " & GUICtrlRead($input)
        GUICtrlSetData($output,$outputtext)
        GUICtrlSetData($input,"")
        If $line = "Y" Or $line = "Yes" Then
            $outputtext = $outputtext & @CRLF & "Loading the character creation screen..." & @CRLF
            GUICtrlSetData($output,$outputtext)
            $NG = 1
            ExitLoop
        ElseIf $line = "N" Or $line = "No" Then
            $outputtext = $outputtext & @CRLF & "Loading the save game selection screen..." & @CRLF
            GUICtrlSetData($output,$outputtext)
            $NG = 2
            ExitLoop
        Else
            $outputtext = $outputtext & @CRLF & "I didn't quite get that, could you try again?" & @CRLF
            GUICtrlSetData($output,$outputtext)
            $outputtext = $outputtext & @CRLF & "Would you like to start a new game? Y/N" & @CRLF
            GUICtrlSetData($output,$outputtext)
        EndIf
EndSelect
WEnd

If $NG = 1 Then ; loads a new game
    CharacterCreate()
ElseIf $NG = 2 Then ; loads a saved game
    $CPFile = FileOpenDialog( "Open Saved Game", $CPDir, "*.cprf")
EndIf
Link to comment
Share on other sites

  • Moderators

DoubleMcLovin,

Difficult to say without seeing more code, but from your post I assume you have a number of GUIs open simultaneously. If this the case, then you may well need to use the advanced parameter with GUIGetMsg so you can determine which GUI has sent what message.

At the moment, receiving the $GUI_EVENT_CLOSE message from any window will fire the Exit code - which could well be the problem.

Here is a short example of using GUIGetMsg with the advanced parameter to show how to use it:

#include <GUIConstantsEx.au3>

Global $hGUI2 = 9999, $hButton3 = 9999 ; Predeclare the variables with dummy values to prevent firing the Case statements

gui1()

Func gui1()

    $hGUI1 = GUICreate("Gui 1", 500, 500)
    $hButton1 = GUICtrlCreateButton("Show Gui 2", 10, 10, 80, 30)
    $hButton2 = GUICtrlCreateButton("Msgbox 1", 10, 60, 80, 30)
    GUISetState()

    While 1
        $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array
        Switch $aMsg[1] ; check which GUI sent the message
            Case $hGUI1
                Switch $aMsg[0] ; Now check for the messages for $hGUI1
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $hButton1
                        GUICtrlSetState($hButton1, $GUI_DISABLE)
                        gui2()
                    Case $hButton2
                        MsgBox("", "MsgBox 1", "Test from Gui 1")
                EndSwitch
            Case $hGUI2
                Switch $aMsg[0] ; Now check for the messages for $hGUI2
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($hGUI2)
                        GUICtrlSetState($hButton1, $GUI_ENABLE)
                    Case $hButton3
                        MsgBox("", "MsgBox", "Test from Gui 2")
                EndSwitch
        EndSwitch
    WEnd

EndFunc   ;==>gui1

Func gui2()

    $hGUI2 = GUICreate("Gui 2", 200, 200, -1, -1)
    $hButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30)
    GUISetState()

EndFunc   ;==>gui2

I hope this helps. :blink:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...