Sign in to follow this  
Followers 0
evilertoaster

GuiCtrlOnEvent not working

39 posts in this topic

Hey, i posted this same question a while back but it was not answered and now I'm needing a solution to it agian...

Here's the sample code-

#include <GUIConstants.au3>
opt ("Guioneventmode",1)
;make GUI1
$GUI1=GUICreate("GUI1")
$button1=GUICtrlCreateButton("button1", 50, 50)
GUICtrlSetOnEvent($button1, "action1")

;Make GUI2
$GUI2 = GUICreate("GUI2")
$button2=GUICtrlCreateButton("button2", 50, 50)
GUICtrlSetOnEvent($button2,"action2")

;Show GUI1
GUIsetstate(@SW_SHOW,$GUI1)

;Wait around
While 1
    sleep (1000)
WEnd

;Button1 is pressed...
func action1 ()
    GUISetState(@SW_SHOW,$GUI2)
;show GUI2 then wait around
    while 1
        sleep (1000)
    WEnd
endfunc

;when button2 is pressed this function IS NOT CALLED
func action2 ()
    MsgBox(0,"OK","You pressed button2")
endfunc

Basically it won't call my action2() function when I press a button...

any ideas?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Case $msg = $Button1

action1()

Case $msg = $Button2

action2()

You can use this way to do it.

Edited by kcd-clan

Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites

Hey, i posted this same question a while back but it was not answered and now I'm needing a solution to it agian...

Why not revive that thread?

Anyway, due to your endless loop, action1 never ends.

Ditch the loop and action2 will launch properly.

Not sure if you plan to add actual code to action1, but you could accomplish the same thing in your main loop.

#include <GUIConstants.au3>
opt ("Guioneventmode",1)
opt ("TrayIconDebug",1)
local $bGUI2Active = 0

;make GUI1
$GUI1=GUICreate("GUI1")
$button1=GUICtrlCreateButton("button1", 50, 50)
GUICtrlSetOnEvent($button1, "action1")

;Make GUI2
$GUI2 = GUICreate("GUI2")
$button2=GUICtrlCreateButton("button2", 50, 50)
GUICtrlSetOnEvent($button2,"action2")

;Show GUI1
GUIsetstate(@SW_SHOW,$GUI1)

;Wait around
While 1
    sleep (1000)
    if $bGUI2Active Then
        ; Insert the code you were going to put in action1()     
        ;~     while 1
        ;~         sleep (1000)
        ;~     WEnd
    EndIf
WEnd

;Button1 is pressed...
func action1 ()
    ;show GUI2 then don't wait around
    GUISetState(@SW_SHOW,$GUI2)
    $bGUI2Active = 1
endfunc

;when button2 is pressed this function IS NOT CALLED
func action2 ()
    MsgBox(0,"OK","You pressed button2")
endfunc

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Case $msg = $Button1

action1

Case $msg = $Button2

action2

I think not?

opt ("Guioneventmode",1)

Different GUI mode.... Edited by evilertoaster

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

;make GUI1
$GUI1=GUICreate("GUI1")
$button1=GUICtrlCreateButton("button1", 50, 50)

;Make GUI2
$GUI2 = GUICreate("GUI2")
$button2=GUICtrlCreateButton("button2", 50, 50)

;Show GUI1
GUIsetstate(@SW_SHOW,$GUI1)

;Wait around
While 1
    $msg = GuiGetMsg()
    Select
Case $msg = $Button1
    action1()
Case $msg = $Button2
    action2()
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;;;;;
    EndSelect
WEnd
Exit

;Button1 is pressed...
func action1 ()
    GUISetState(@SW_SHOW,$GUI2)
;show GUI2 then wait around
 
endfunc

;when button2 is pressed this function IS NOT CALLED
func action2 ()
    MsgBox(0,"OK","You pressed button2")
endfunc


Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites

$gui=1
#include <GUIConstants.au3>
;make GUI1
$GUI1=GUICreate("GUI1")
$button1=GUICtrlCreateButton("button1", 50, 50)

;Make GUI2
$GUI2 = GUICreate("GUI2")
$button2=GUICtrlCreateButton("button2", 50, 50)

;Show GUI1
GUIsetstate(@SW_SHOW,$GUI1)

;Wait around
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $Button1
    action1()
Case $msg = $Button2
    action2()
Case $msg = $GUI_EVENT_CLOSE
        If $gui=1 Then
        ExitLoop
    EndIf
    If $gui=2 Then
        GUIsetstate(@SW_HIDE,$GUI2)
        $gui=1
    EndIf
    Case Else
    ;;;;;;;
    EndSelect
WEnd
Exit

;Button1 is pressed...
func action1 ()
    $gui=2
    GUISetState(@SW_SHOW,$GUI2)

;show GUI2 then wait around
 
endfunc

;when button2 is pressed this function IS NOT CALLED
func action2 ()
    MsgBox(0,"OK","You pressed button2")
endfunc

a better one.


Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Why not revive that thread?

Anyway, due to your endless loop, action1 never ends.

Ditch the loop and action2 will launch properly.

Not sure if you plan to add actual code to action1, but you could accomplish the same thing in your main loop.

#include <GUIConstants.au3>
opt ("Guioneventmode",1)
opt ("TrayIconDebug",1)
local $bGUI2Active = 0

;make GUI1
$GUI1=GUICreate("GUI1")
$button1=GUICtrlCreateButton("button1", 50, 50)
GUICtrlSetOnEvent($button1, "action1")

;Make GUI2
$GUI2 = GUICreate("GUI2")
$button2=GUICtrlCreateButton("button2", 50, 50)
GUICtrlSetOnEvent($button2,"action2")

;Show GUI1
GUIsetstate(@SW_SHOW,$GUI1)

;Wait around
While 1
    sleep (1000)
    if $bGUI2Active Then
        ; Insert the code you were going to put in action1()     
        ;~     while 1
        ;~         sleep (1000)
        ;~     WEnd
    EndIf
WEnd

;Button1 is pressed...
func action1 ()
    ;show GUI2 then don't wait around
    GUISetState(@SW_SHOW,$GUI2)
    $bGUI2Active = 1
endfunc

;when button2 is pressed this function IS NOT CALLED
func action2 ()
    MsgBox(0,"OK","You pressed button2")
endfunc
Hummm, so you can't call a new function untill after action 1 is returned...

here's the thing- in my actual code it goes somthing like this- (sorry for the wierd formating but it gets the point across i hope...the actual script is over 1200 lines :D )-

Pseudocode-
<script start>
<Makes 2 GUIs>
<Show GUI 1>
<Loop forever (wait for event from GUI 1 to be called)>
-----------
<event from GUI1 is called>
<Hide GUI1, show GUI2>
<GUI2 has a button that is set to call function "pausef"
<A long series of actions is performed, after every few lines I add a check to see if $pause=1, if it does it calls the 'wait' function>
-----------
function pausef
      if $pause=0 then
           $pause=1
      else
           $pause=0
      endif
endfunc
---------------
func wait
      while 1
            sleep(1000)
            if $pause=0 return
       wend
endfunc
Edited by evilertoaster

Share this post


Link to post
Share on other sites

You are trying to create 2 main GUIs, the problem is there somewhere. I don't think you can have 2 main GUIs, only a Parent and then children of that parent.

There is nothing wrong with the coding for the button creation or the events as far as I can tell.

Nomad :D


Share this post


Link to post
Share on other sites

You can do somthing like

in your case just set it with it to where the buttion reacts function.

HotKeySet("{PAUSE}","pause")

Func pause()
    ToolTip("paused")
    $pause=1
    Do
        HotKeySet("{PAUSE}","pause1")
    Until $pause=0
    HotKeySet("{PAUSE}","pause")

EndFunc

Func pause1()
 $pause=0
 ToolTip("")
EndFunc

While 1
WEnd

Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites

You are trying to create 2 main GUIs, the problem is there somewhere. I don't think you can have 2 main GUIs, only a Parent and then children of that parent.

There is nothing wrong with the coding for the button creation or the events as far as I can tell.

Nomad :D

you can have 1024 GUIs according to the help file

Share this post


Link to post
Share on other sites

You can do somthing like

in your case just set it with it to where the buttion reacts function.

HotKeySet("{PAUSE}","pause")

Func pause()
    ToolTip("paused")
    $pause=1
    Do
        HotKeySet("{PAUSE}","pause1")
    Until $pause=0
    HotKeySet("{PAUSE}","pause")

EndFunc

Func pause1()
 $pause=0
 ToolTip("")
EndFunc

While 1
WEnd
yes in fact i already have this.

The problem is making it work from a gui button

Share this post


Link to post
Share on other sites

you can have 1024 GUIs according to the help file

But does it say "Parent" GUI's? :D

I only tried what you are trying to do one time, and the controls failed to respond. Since then I always create 1 parent and as many children as I need and haven't had a single problem like this since.

Nomad :D


Share this post


Link to post
Share on other sites

But does it say "Parent" GUI's? :D

I only tried what you are trying to do one time, and the controls failed to respond. Since then I always create 1 parent and as many children as I need and haven't had a single problem like this since.

Nomad :D

I've never really worked with 'parent' or 'child' GUIs...I just make GUI windows :P ....I'll look into it then (it's in the help file i'm guessing?)

Share this post


Link to post
Share on other sites

I've never really worked with 'parent' or 'child' GUIs...I just make GUI windows :D ....I'll look into it then (it's in the help file i'm guessing?)

Yeah, it's not difficult, the child GUI gets named just like a parent GUI, only the last parameter of the child GUICreate() is the name of the parent GUI. Besides that, I have no idea why your, or my, controls failed to work properly.

If someone has created more than one parent GUI at the same time and has no problem operating the controls on either GUI, I'd like to see the script. :D


Share this post


Link to post
Share on other sites

hummm still doesn't seem to be working directly...

opt("GUIONEVENTMODE",1)
$a=GUICreate("Test")
GUICtrlCreateButton("but1",15,15)
GUICtrlSetOnEvent(-1,"f1")
$b=GUICreate("Test2",135,135,5,5,"","",$a)
GUICtrlCreateButton("but2",5,5)
GUICtrlSetOnEvent(-1,"f2")
GUISetState(@SW_SHOW,$a)
While 1
    Sleep(100)
WEnd
func f1()
    GUISetState(@SW_SHOW,$B)
    while 1
        Sleep(1000)
    WEnd
EndFunc
func f2()
    MsgBox(0,"OK","OK"); Still not called....
EndFunc

although maybe like he said it can't call another function until it returns from the first one?

or can am i doing this parent child thing worng?

Share this post


Link to post
Share on other sites

Im working on it and it can be done.

It will pause gui1 and you can still execute other gui

OK...That's kinda what im after i think...(not pausing the GUI per say but rather the whole script flow itself)...

what a nussence :D

Share this post


Link to post
Share on other sites

OK...That's kinda what im after i think...(not pausing the GUI per say but rather the whole script flow itself)...

what a nussence :D

This works:

opt("GUIONEVENTMODE",1)
$a = GUICreate("Test")
GUICtrlCreateButton("but1",15,15)
GUICtrlSetOnEvent(-1,"f1")
$b = GUICreate("Test2",135,135,5,5,-1,"",$a)
GUICtrlCreateButton("but2",5,5)
GUICtrlSetOnEvent(-1,"f2")
GUISetState(@SW_SHOW, $a)
While 1
    Sleep(100)
WEnd
func f1()
    GUISetState(@SW_SHOW, $B)
EndFunc
func f2()
    MsgBox(0,"OK","OK"); Still not called....
EndFunc

Share this post


Link to post
Share on other sites

OK...That's kinda what im after i think...(not pausing the GUI per say but rather the whole script flow itself)...

what a nussence :D

I wrote something that does this - but I have not updated the code in a while, so there is a lot of extra code that is not needed, but I think it might help. By the way if someone could knock it down and show me all the things that I did wrong - I would be greatful.

what is the command to insert long code

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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