Sign in to follow this  
Followers 0
McGod

GUI Event Buttons Problem

5 posts in this topic

#1 ·  Posted (edited)

Ok, so I'm making a login etc, and I seem to have a Event Button Problem. My first GUI (Connecting GUI) buttons work fine. I go through that gui use a GUIDelete () Then run the second GUI, though I click on the button but nothing happens :\ I'm using Events.

All code as of now

#region hi
Global $name = "Abaddon", $G_Connect, $Main, $Local, $B_Connect
#include <String.au3>
#include <GUIConstants.au3>
TCPStartup ()
Opt("GUIOnEventMode", 1)
GUIConnect ()
#endregion

Func GUIconnect ()
$G_Connect = GUICreate($name & "-Connecting", 412, 556, 193, 115)
GUISetFont(10, 800, 0, "Trebuchet MS")
GUICtrlCreateGroup("Connecting", 8, 8, 393, 537)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlCreateGroup("Server List", 16, 32, 377, 161)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$Main = GUICtrlCreateRadio("Main", 32, 56, 113, 17)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$Local = GUICtrlCreateRadio("Local", 32, 80, 113, 17)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$B_Connect = GUICtrlCreateButton("Connect", 152, 200, 91, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlCreateLabel("Choose a server to log on to then hit connect.", 56, 240, 285, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlSetOnEvent ( $B_Connect, "connect" )
GUISetOnEvent ( $GUI_EVENT_CLOSE, "GUIExit" )
GUISetState(@SW_SHOW)
While 1
    Sleep(100)
WEnd
EndFunc

Func connect ()
Select
    Case GUICtrlRead ( $Main ) = $GUI_CHECKED
    $ip = TCPNameToIp ( "abaddon.hopto.org" )
    Case GUICtrlRead ( $Local ) = $GUI_CHECKED
    $ip = @IPAddress1
Case Else
    MsgBox ( 1, $name & "-Error", "You must choose a server!" )
    Return
EndSelect
$sock = TCPConnect ( $ip, 2548 )
If $sock = -1 Then
MsgBox ( 1, $name & "-Error", "The server you are trying to connect to is offline" & @CRlf & "Please check the Outages forum" )
Return
Else
GUIDelete ()
loginscreen ()
EndIf
EndFunc

Func GUIExit ()
Exit
EndFunc

Func loginscreen ()
$G_Login = GUICreate($name & "-Login", 405, 523, 194, 114)
GUISetFont(10, 800, 0, "Trebuchet MS")
GUICtrlCreateGroup("Login", 8, 8, 385, 505)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$I_Username = GUICtrlCreateInput("Username", 136, 64, 121, 26)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlCreateLabel("Username", 136, 40, 65, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlCreateLabel("Password", 136, 104, 62, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$I_Password = GUICtrlCreateInput("Password", 136, 128, 121, 26)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlCreateGroup("Buttons", 104, 168, 185, 193)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$B_Submit = GUICtrlCreateButton("Submit", 120, 192, 155, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$B_NewAccount = GUICtrlCreateButton("New Account", 120, 224, 155, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$B_ReturnC = GUICtrlCreateButton("Return", 120, 256, 155, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
$B_Exit = GUICtrlCreateButton("Exit", 120, 288, 155, 25, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Trebuchet MS")
GUICtrlSetOnEvent ( $B_Submit, "login" )
GUICtrlSetOnEvent ( $B_NewAccount, "newacct" )
GUICtrlSetOnEvent ( $B_ReturnC, "GUIreturn" )
GUICtrlSetOnEvent ( $B_Exit, "GUIExit" )
GUISetOnEvent ( $GUI_EVENT_CLOSE, "GUIExit" )
GUISetState(@SW_SHOW)
While 1
    Sleep(100)
WEnd
EndFunc

Func GUIReturn ()
Switch @GUI_CtrlId
    Case $B_ReturnC
    GUIDelete ()
    GUIConnect ()
Case Else
;;
EndSwitch
EndFunc

Func login ()
MsgBox ( 1, "Login", "Login" )
EndFunc

Func newacct ()
MsgBox ( 1, "Acct", "New ACct" )
EndFunc

Its an autoit game client atm. though I just started.

TCPStartup ()
If @Error = 1 then Exit MsgBox ( 1, "Error", "Character Server failed to start!" )
$sock = TCPListen ( @IpAddress1, "2548" )
If $sock = -1 Then Exit MsgBox ( 1, "Error", "Character Server failed to start!" )
While 1
$accept = TCPAccept ( $sock )
Sleep (100)
WEnd

OH and how would i make a universal $GUI_EVENT_CLOSE for all my GUIs

Edited by Chip

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I ran into this problem the other day... I am not sure exactly what the problem is, if there is a problem, and if there is, if it's been reported.

Here's a small example script (always best to do that than post long drawn out code that no one wants to use to debug).

Opt('GUIONEVENTMODE', 1)
Global $SUBBUTTON, $MAINBUTTON
_MainGUI()

Func _MainGUI()
    $MAINGUI = GUICreate('MY MAIN GUI', 200, 100)
    $MAINBUTTON = GUICtrlCreateButton('SWITCH TO SUB GUI', 35, 35, 125, 30)
    GUISetOnEvent(-3, '_EXITNOW', $MAINGUI)
    GUICtrlSetOnEvent($MAINBUTTON, '_MAINEVENTS')
    GUISetState()
    While 1
        Sleep(1000)
    WEnd
EndFunc

Func _SUBGUI()
    $SUBGUI = GUICreate('MY SUB GUI', 200, 100)
    $SUBBUTTON = GUICtrlCreateButton('SWITCH TO MAIN GUI', 35, 35, 125, 30)
    GUISetOnEvent(-3, '_EXITNOW', $SUBGUI)
    GUICtrlSetOnEvent($SUBBUTTON, '_SUBEVENTS')
    GUISetState(@SW_SHOW, $SUBGUI)
    While 1
       Sleep(1000)
    WEnd
EndFunc

Func _MAINEVENTS()
    Switch @GUI_CtrlId
        Case $MAINBUTTON
            GUIDelete(@GUI_WinHandle)
            _SUBGUI()
    EndSwitch
EndFunc

Func _SUBEVENTS()
    Switch @GUI_CtrlId
        Case $SUBBUTTON
            GUIDelete(@GUI_WinHandle)
            _MainGUI()
    EndSwitch
EndFunc

Func _EXITNOW()
    Exit
EndFunc
I was hiding the main window initially, moved to setting oneventmode to 0 and then 1 again within the function, I tried to disable the original window, and then decided to try and just delete the original gui (the above example shows)... none of the 4 above methods worked for myself. It's like it's not letting go of the first GUI handle.

Edit:

Oh... lol - My solution was to disable OnEventMode when I went to my sub gui, and switch to GUIGetMsg() and switch/endswitch. Then Enable OnEventMode upon my return to the original GUI.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I found my error kinda like yours:

See I did one of theses

GUI 1 loaded GUI 2 using an OnEvent, which meant my whole script was interupted after i loaded GUI 2.

So i loaded all my guis at the beginning and use States. Works fine :):P

Share this post


Link to post
Share on other sites

I found my error kinda like yours:

See I did one of theses

GUI 1 loaded GUI 2 using an OnEvent, which meant my whole script was interupted after i loaded GUI 2.

So i loaded all my guis at the beginning and use States. Works fine :):P

Yeah, that's a tad inconvenient I think for me, I'll stick to good old GUIGetMsg() for Multiples, or maybe the work around I stated above if I'm feeling frisky.... I am thinking I remember Valik saying something about this several months ago, but I can't remember where the thread was or when it was for that matter.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

wow, i looked at this for a while... i never have seen this before

i guess i have always set the GUI's first then used show/hide etc

8)


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