Sign in to follow this  
Followers 0
JustinReno

GuiCtrlSetOnEvent

6 posts in this topic

#1 ·  Posted (edited)

I'm creating a slideshow creator for my friend. I need to use GuiCtrlSetOnEvent for my functions. Well, I was looking around, and GuiCtrlSetOnEvent adds the () at the end of the function. That causes a problem, my functions have parameters and it doesn't work. Maybe its just me but is there anyother way? Here is some test code:

#Include <GuiConstants.au3>

$Gui = GuiCreate("Testing GUICtrlSetOnevent", 500, 500)
$Button_One = GUICtrlCreateButton("Click", 0, 0)
$Button_Two = GUICtrlCreateButton("Click_2", 0, 20)
GUISetState()

GUICtrlSetOnEvent($Button_One, "Message(""1"")")
GUICtrlSetOnEvent($Button_Two, "Message(""1"")")

While 1
    Sleep(10)
WEnd

Func Message($Param1)
    If $Param1 = "1" Then MsgBox(0, "Testing GuiCtrlSetOnEvent", "Button_One clicked")
    If $Param1 = "2" Then MsgBox(0, "Testing GuiCtrlSetOnEvent", "Button_Two clicked")
EndFunc

Edit: And this is the only way I can code the function. <_<

Edited by JustinReno

Share this post


Link to post
Share on other sites

I'm sure you don't "need" OnEvent. GUIGetMsg() used properly will work for you I'm sure.

But the short answer is "no" you can't use parameters with OnEvent as you are wanting.

But you could set up some type of manager function to do what you need I'm sure, only problem is, you'll be playing with unnecessary globals then.


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.

Share this post


Link to post
Share on other sites

Like this...

#Include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$Gui = GuiCreate("Testing GUICtrlSetOnevent", 500, 500)
$Button_One = GUICtrlCreateButton("Click_1", 0, 0)
$Button_Two = GUICtrlCreateButton("Click_2", 0, 30)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

GUICtrlSetOnEvent($Button_One, "Send_Message")
GUICtrlSetOnEvent($Button_Two, "Send_Message")

While 1
    Sleep(10)
WEnd

Func Send_Message()
    $info = @GUI_CtrlId -2
    Message($info)
EndFunc

Func SpecialEvents()
    Exit
EndFunc

Func Message($Param1)
    If $Param1 = "1" Then MsgBox(0, "Testing GuiCtrlSetOnEvent", "Button_One clicked")
    If $Param1 = "2" Then MsgBox(0, "Testing GuiCtrlSetOnEvent", "Button_Two clicked")
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#Include <GuiConstants.au3>
Opt("GUIOnEventMode",1)
$Gui = GuiCreate("Testing GUICtrlSetOnevent", 500, 500)
$Button_One = GUICtrlCreateButton("Click", 0, 0)
$Button_Two = GUICtrlCreateButton("Click_2", 0, 30)
GUISetState()

GUICtrlSetOnEvent($Button_One, "Message")
GUICtrlSetOnEvent($Button_Two, "Message")

While 1
    Sleep(10)
WEnd

Func Message()
    switch @GUI_CTRLID
          Case $Button_One
             MsgBox(0, "Testing GuiCtrlSetOnEvent", "Button_One clicked")
          Case $Button_Two
        MsgBox(0, "Testing GuiCtrlSetOnEvent", "Button_Two clicked")
        EndSwitch
EndFunc

Whoops, sorry Valuater, didn't see your reply.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Whoops, sorry Valuater, didn't see your reply.

lol, yours actually looks cleaner!

8)

BTW, it might "look" nicer if you use [ autoit] tags

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks!

@Smoke_N: This is the only way I could code the function. GUIGetMsg will NOT work. Its a multitasker and won't work with GUIGetMsg.

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