Jump to content
Sign in to follow this  
newb_powa'

Problem with OnEvent

Recommended Posts

newb_powa'

Ok, I'll start by explaining what I want to do, At the right of the gui, there is 3 little arrow ">" (label) wich are my labels. When I hit one of this arrow It do not work, but it should close the gui and make another. I don't know if you can understand me ... There is my script it will certainly help you to understand what I want to do.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

$SWITCH = 1
$x = 1
$y = 635

_Switch2()

While 1
    If WinExists("Ogame Bot") Then WinMove("Ogame Bot", "", $x, $y)
    If WinExists(".") Then WinMove(".", "", $x+1000, $y)
    Sleep(1)
WEnd


Func _Switch()
    If WinExists("Ogame Bot") Then WinClose("Ogame Bot")
    ;========================== Gui #2 ==========================
    ;GuiCreate
    $Form2 = GUICreate(".", 22, 154, $x+1000, $y, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
    
    ;LabelCreate
    $9 = GUICtrlCreateLabel("<", 8, 8 , 20, 20)
    $10= GUICtrlCreateLabel("<", 8, 48, 20, 20)
    $11= GUICtrlCreateLabel("<", 8, 88, 20, 20)
    
    ;SetBkColor
    $Color = 0xA0A0A4
    GUISetBkColor($Color)
    GUICtrlSetBkColor($9 , $Color)
    GUICtrlSetBkColor($10, $Color)
    GUICtrlSetBkColor($11, $Color)
    
    ;SetFontColor
    $C0l0r = 0xFFFFFF
    GUICtrlSetColor($9 , $C0l0r)
    GUICtrlSetColor($10, $C0l0r)
    GUICtrlSetColor($11, $C0l0r)
    
    ;State
    WinSetState($Form2, "", @SW_SHOW)
    WinSetOnTop($Form2, "", 1)

    ;Events
    GUICtrlSetOnEvent($9 , "_Switch2")
    GUICtrlSetOnEvent($10, "_Switch2")
    GUICtrlSetOnEvent($11, "_Switch2")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
EndFunc
    
Func _Switch2()
    If WinExists(".") Then WinClose(".")
    ;========================== Gui #1 ==========================
    ;GuiCreate
    $Form1 = GUICreate("Ogame Bot", 1026, 154, $x, $y, BitOR($WS_MAXIMIZEBOX,$WS_TABSTOP), $WS_EX_TOOLWINDOW)
    
    ;GroupCreate
    $GroupTous1 =   GUICtrlCreateGroup("", 640, 0, 361, 105)
    $CristalGroup = GUICtrlCreateGroup("Cristal ", 824, 8, 169, 41, $BS_CENTER)
    $EnergieGroup = GUICtrlCreateGroup("Énergie ", 824, 56, 169, 41, $BS_CENTER)
    $DeutGroup =    GUICtrlCreateGroup("Deutérieum ", 648, 56, 169, 41, $BS_CENTER)
    $MetalGroup =   GUICtrlCreateGroup("Métal ", 648, 8, 169, 41, $BS_CENTER)
    $Group1 =       GUICtrlCreateGroup("Actions ", 8, 0, 505, 105)
    $1 = GUICtrlCreateGroup("", -99, -99, 1, 1)
    $2 = GUICtrlCreateGroup("", -99, -99, 1, 1)
    $3 = GUICtrlCreateGroup("", -99, -99, 1, 1)
    $4 = GUICtrlCreateGroup("", -99, -99, 1, 1)
    $5 = GUICtrlCreateGroup("", -99, -99, 1, 1)
    
    ;LabelCreate
    $CristalLabel = GUICtrlCreateLabel("ALabel1", 832, 24, 43, 17, $BS_CENTER)
    $EnergieLabel = GUICtrlCreateLabel("ALabel1", 832, 72, 43, 17, $BS_CENTER)
    $DeutLabel =    GUICtrlCreateLabel("ALabel1", 656, 72, 43, 17, $BS_CENTER)
    $MetalLabel =   GUICtrlCreateLabel("ALabel1", 656, 24, 43, 17, $BS_CENTER)
    $lineLabel =    GUICtrlCreateLabel("------------------------------------", 520, 32, 112, 17)
    $6 = GUICtrlCreateLabel(">", 1008, 8 , 20, 20)
    $7 = GUICtrlCreateLabel(">", 1008, 48, 20, 20)
    $8 = GUICtrlCreateLabel(">", 1008, 88, 20, 20)
    
    ;ComboBoxCreate
    $Combo1 = GUICtrlCreateCombo("Planet 1", 520, 8, 113, 21)
    
    ;EditBoxCreate
    $Edit1 = GUICtrlCreateEdit("", 16, 16, 489, 81, $ES_READONLY, $WS_EX_CLIENTEDGE)
    
    ;ButtonsCreate
    $Button1 = GUICtrlCreateButton("Change Actions", 520, 48, 113, 25)
    $Button2 = GUICtrlCreateButton("Go", 520, 80, 113, 25)
    
    ;SetBkColor
    $Color = 0xA0A0A4
    GUISetBkColor    ($Color)
    GUICtrlSetBkColor($GroupTous1,   $Color)
    GUICtrlSetBkColor($CristalGroup, $Color)
    GUICtrlSetBkColor($CristalLabel, $Color)
    GUICtrlSetBkColor($EnergieGroup, $Color)
    GUICtrlSetBkColor($EnergieLabel, $Color)
    GUICtrlSetBkColor($DeutGroup,  $Color)
    GUICtrlSetBkColor($DeutLabel,  $Color)
    GUICtrlSetBkColor($MetalGroup, $Color)
    GUICtrlSetBkColor($MetalLabel, $Color)
    GUICtrlSetBkColor($Group1,     $Color)
    GUICtrlSetBkColor($lineLabel,  $Color)
    GUICtrlSetBkColor($6,  $Color)
    GUICtrlSetBkColor($7,  $Color)
    GUICtrlSetBkColor($8,  $Color)
    
    ;SetFontColor
    $C0l0r = 0xFFFFFF
    GUICtrlSetColor($CristalGroup, $C0l0r)
    GUICtrlSetColor($CristalLabel, $C0l0r)
    GUICtrlSetColor($EnergieGroup, $C0l0r)
    GUICtrlSetColor($EnergieLabel, $C0l0r)
    GUICtrlSetColor($DeutGroup,    $C0l0r)
    GUICtrlSetColor($DeutLabel,    $C0l0r)
    GUICtrlSetColor($MetalGroup,   $C0l0r)
    GUICtrlSetColor($MetalLabel,   $C0l0r)
    GUICtrlSetColor($Group1,       $C0l0r)
    GUICtrlSetColor($lineLabel,    $C0l0r)
    GUICtrlSetColor($6, $C0l0r)
    GUICtrlSetColor($7, $C0l0r)
    GUICtrlSetColor($8, $C0l0r)
    
    ;SetData
    GUICtrlSetData($Combo1,"Planet 2|Planet 3|Planet 4|Planet 5|Planet 6|Planet 7|Planet 8","Planet 1")
    GUICtrlSetData($Edit1, "AEdit1")
    
    ;State
    WinSetState($Form1, "", @SW_SHOW)
    WinSetOnTop($Form1, "", 1)
    
    ;Events
    GUICtrlSetOnEvent($6, "_Switch")
    GUICtrlSetOnEvent($7, "_Switch")
    GUICtrlSetOnEvent($8, "_Switch")
    GUICtrlSetOnEvent($Button1, "_Action")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
EndFunc

    
Func _Action()
    MsgBox(0, "", "It Work")
EndFunc

    
Func _Close()
    Exit
EndFunc

Feel free to ask question and thanks for help :P. Sorry for bad english ...

Oh and I think this is really my OnEvent that don't work (I don't know why ??) because I made a little test with the first button and it don't do anything.

Share this post


Link to post
Share on other sites
Uten

Try this:

Adding a global gui reference:

Global $gGui = _Switch2()oÝ÷ Ø]xºÚ"µÍ    ÌÍÙÑÝZHH   ÌÍÑÜLB  ÌÍÙÑÝZHH   ÌÍÑÜLoÝ÷ ØÊü­ë-jס׺Ú"µÍÔÝ]BÕÚ[Ù]Ý]J    ÌÍÑÜLK  ][ÝÉ][ÝËÕ×ÔÒÕÊBÕÚ[Ù]ÛÜ
    ÌÍÑÜLK  ][ÝÉ][ÝËJBÑ][ÂÕRPÝÙ]Û][
    ÌÍÍ  ][Ý×ÔÝÚ]Ú ][ÝÊBÕRPÝÙ]Û][
    ÌÍÍË    ][Ý×ÔÝÚ]Ú ][ÝÊBÕRPÝÙ]Û][
    ÌÍΠ ][Ý×ÔÝÚ]Ú ][ÝÊBÕRPÝÙ]Û][
    ÌÍÐ]ÛK  ][Ý×ÐXÝ[Û][ÝÊBÕRTÙ]Û][
    ÌÍÑÕRWÑUSÐÓÔÑK ][Ý×ÐÛÜÙI][ÝÊBBQÕRTÙ]Ý]JÕ×ÔÒÕÊBÚ[Ù]ÛÜ
    ÌÍÑÜLK  ][ÝÉ][ÝËJoÝ÷ Ø   e¡ù²b~'¶*'

Share this post


Link to post
Share on other sites
newb_powa'

Ok, I'm not sure but if I'm right, a bad declaration a variable can affect gui Event ?? Anyway now it work so thank you :P !!

And is consolewrite really need ? or just here for testing ??

Share this post


Link to post
Share on other sites
Uten

ConsoleWrite was just for testing.

The diffrence with the 4gGui is in the way the two gui's are closed. Your way would terminate the application. There are probably other ways to..:P

Share this post


Link to post
Share on other sites
newb_powa'

ConsoleWrite was just for testing.

The diffrence with the 4gGui is in the way the two gui's are closed. Your way would terminate the application. There are probably other ways to..:P

Ok now I understand, thank you Uten :D

Share this post


Link to post
Share on other sites
Uten

I think your OnEvent code failed because you did not call GuiSetState after you had defined the event handler.

Share this post


Link to post
Share on other sites
newb_powa'

I think your OnEvent code failed because you did not call GuiSetState after you had defined the event handler.

I'll remember :P

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  

×