Jump to content

How to pass variables to functions when in Guioneventmode


Recommended Posts

  • Moderators

How do I pass a variable to a function, when using guionevent mode?!?

Magic?

Have an example of what you are talking about specifically?

Most create an _EventHandler() function (Similar to SpecialEvents() shown in the GUICtrlSetOnEvent example in the help file), that when setting their GUICtrlSetOnEvent() they use the _EventHandler() function to capture the @GUI_CTRLID, and call the functions with the needed parameters from there.

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.

Link to comment
Share on other sites

  • 4 months later...

I am working on a client script, for use with IRC as a test network for now...

But I need to have working buttons on Message windows like:

Send (reference the main input for text, send to server, and add to the main edit, and clear the main input)

and

Clear screen (clear the main edit)

I would like to use the @GUI_WINHANDLE, @GUI_CTRLHANDLE or @GUI_CTRLID to find the control ID's or handles of other controls on my message windows but I'm not sure how to retrieve the ID's of specific controls...

Especially, since every message window tends to have randomly picked ID's and handles for each control.

GUIGetMsg works, but OnEvent would make the code cleaner, easier and more efficient.

Any idea how to retrieve specific control information of the window from an OnEvent by button?

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Sample Code: (Modified From Help)

#include <GUIConstants.au3>

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)

$parent1 = GUICreate("Parent1")

$Test1 = GUICtrlCreateButton ("OK",  10, 30, 50)
GUICtrlSetOnEvent(-1, "FuncWithParameter")
$Test2 = GUICtrlCreateButton ( "Cancel",  0, -1)
GUICtrlSetOnEvent(-1, "FuncWithParameter")
$Test3 = GUICtrlCreateInput("",-50,40,300,30)
GUICtrlSetOnEvent(-1, "FuncWithParameter")
GUISetState(@SW_SHOW)


; Just idle around
While 1
    Sleep(10)
Wend

Func FuncWithParameter()
    Switch @GUI_CTRLID
        Case $Test1      
            Function(GUICtrlRead($Test3)) ; Parameters Go Here
        Case $Test2
            MsgBox(0, "Cancel Pressed","You Pressed Cancel!")
    EndSwitch
EndFunc


Func Function($Parameter)
    MsgBox(0, "InputFunction", $Parameter )
EndFunc

The "FuncWithParameter" Function is an event handling function like Smoke_N was talking about.

Link to comment
Share on other sites

  • 3 weeks later...

Yes, an expected/applicable answer for just one GUI...

but when you're making many, many similar GUI's (as stated above, instant messaging windows) it would become redundant to write out all of the dialog's controls manually; rather than spend hours in something not necessarily possible given conditions, I used a temporary fix I guessed at while debating the issue...

I assigned an list of the control ID's on each GUI to an array with a variable name similar to the ID of a GUI event....

using the @GUI_CTRLID macro I was able to retrieve the array with all the control ID information for each specific seperate window...

this allows me currently with an easy way for each GUI to handle itself without interfering with anything else or creating more than one function for each event.

So I could have 1, or 20 Instant Message windows all capable of sustaining theirselves and their own triggers based upon their own content.

For now it works passably although, I would have found it simpler if I could have retrieved the control ID's on the same seperate GUI's though more macros rather than create temporary arrays.

Thanks Anyway. :)

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

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