Jump to content

Trayitemsetonevent


Recommended Posts

Hey,

Is there a way to make execute a function with parameter with TrayItemSetOnEvent($something,"ExitScript")? All examples show only functions that are without any parameter and i couldn't find any way around it?

Thank you

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Hey,

Is there a way to make execute a function with parameter with TrayItemSetOnEvent($something,"ExitScript")? All examples show only functions that are without any parameter and i couldn't find any way around it?

Thank you

Maybe this help:

Opt ("TrayMenuMode",1)
Opt ("TrayOnEventMode",1)
$item1=TrayCreateItem ("Close")
TrayItemSetOnEvent ($item1,"ExitScript")

While 1
    Sleep (300)
WEnd

Func ExitScript ($param=0)
    If Not IsDeclared ("param") Then
        Call ("ExitScript", 0); here put your params
        Return
    EndIf
    
    If Not $param=0 Then
        Return False
    Else
        MsgBox (0,"Message","Script is finished by user")
        Exit
    EndIf
EndFunc

Were you looking for something like that?

Edited by elgabionline
Link to comment
Share on other sites

Were you looking for something like that?

Well not quite (or maybe i don't understand it fully). Normally calling a function is like SomeGreatFunction() or SomeGreatFunction($some_value_that_will_be_used_in_this_function). In the TrayItemSetOnEvent($something,"ExitScript") function is in between " which is a bit weird (considering other uses) and you can't make it like TrayItemSetOnEvent($something,"ExitScript($some_value)") and i want to be able to call it that way.

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Well not quite (or maybe i don't understand it fully). Normally calling a function is like SomeGreatFunction() or SomeGreatFunction($some_value_that_will_be_used_in_this_function). In the TrayItemSetOnEvent($something,"ExitScript") function is in between " which is a bit weird (considering other uses) and you can't make it like TrayItemSetOnEvent($something,"ExitScript($some_value)") and i want to be able to call it that way.

I understand, but AutoIt doesn't allow to send parameters with these functions (TraySetOnEvent, HotkeySet, GuiSetOnEvent. . . ) because it ignores them.

The better thing would be if this piece of code worked:

TrayItemSetOnEvent ($item1, Call ("ExitScript", $something))

But there's not way, my friend. .

Link to comment
Share on other sites

  • 11 months later...
  • Developers

Or they could just FIX it :) I asked a long time ago and got no response. These functions should DEFINATELY accept parameters.

It does not .....

:D

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I know... I said they SHOULD. And they WOULD if ya'll added it.

There's no reasonable workaround either, which makes it a double kick in the nards. Someone once proposed a wrapper function but you would need a unique wrapper function for each case, and then that goes against what "functions" are for in the first place. The only other way I could think of was to write the parameter to a variable before calling the function then having the function read the variable - and that is the parameter... but that's both clumsy and unreliable.

Link to comment
Share on other sites

  • Developers

I know... I said they SHOULD. And they WOULD if ya'll added it.

There's no reasonable workaround either, which makes it a double kick in the nards. Someone once proposed a wrapper function but you would need a unique wrapper function for each case, and then that goes against what "functions" are for in the first place. The only other way I could think of was to write the parameter to a variable before calling the function then having the function read the variable - and that is the parameter... but that's both clumsy and unreliable.

Can't you have one and test the @TRAY_ID ?

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Or they could just FIX it :) I asked a long time ago and got no response. These functions should DEFINATELY accept parameters.

I'm not sure it really makes sense. The function called does have access to all the macros and global variables of the script, including @TRAY_ID to indicate which tray item it was (if the same function was set for more than one item). What would you pass to the OnEvent function that the called function wouldn't have access to anyway? If you could do something like this:

TrayItemSetOnEvent($ItemID, _MyTrayFunc($var1, 0x1A2B, $var2))

Func _MyTrayFunc($Input1, $Input2, $Input3)
    ; ...
EndFuncoÝ÷ Ùhrr¥v}ý·*.ë-jDz)rv­)¶¬jëh×6TrayItemSetOnEvent($ItemID, "_MyTrayFunc")

Func _MyTrayFunc()
    Local $Input1 = $var1
    Local $Input2 = 0x1A2B
    Local $Input3 = $var2
    ; ...
EndFunc   ;==>_MyTrayFunc

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Because then you have ONE function per menu item call... again, what are functions for? They are there so we can make efficient modular use of them, otherwise why use functions at all - we may as just well go back to 2.64

What if I have a 2000 line function called "myBackup" and in the menu item I want "backup now", "backup in 10 minutes" and "backup in an hour"? Do I now need 6000 lines of code? Why? The 2000 lines is all I need, running slightly different based on a parameter it accepts

func myBackup($when) ...

How you are proposing it, I would need a WHOLE other function with its own $when for each item.

LD

Link to comment
Share on other sites

  • Developers

Because then you have ONE function per menu item call... again, what are functions for? They are there so we can make efficient modular use of them, otherwise why use functions at all - we may as just well go back to 2.64

What if I have a 2000 line function called "myBackup" and in the menu item I want "backup now", "backup in 10 minutes" and "backup in an hour"? Do I now need 6000 lines of code? Why? The 2000 lines is all I need, running slightly different based on a parameter it accepts

func myBackup($when) ...

How you are proposing it, I would need a WHOLE other function with its own $when for each item.

LD

mmm looks like you are in attack mode today ...

Have you read and understood what was answered ?

The question was if you couldn't use @TRAY_ID in your called function and use one ?

Don't think that this was answered in your last post ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

No, not "attach mode". Sorry if it comes across that way. Just frustrated with how GOOD suggestions are handled. They are often dismissed as useless because they don't apply to the respondant's situation.

And I didn't see your @TRAY_ID suggestion when I responded. Nor do I have a response. Thanks for that, I'll look into it.

LD

Link to comment
Share on other sites

  • Developers

No, not "attach mode". Sorry if it comes across that way. Just frustrated with how GOOD suggestions are handled. They are often dismissed as useless because they don't apply to the respondant's situation.

And I didn't see your @TRAY_ID suggestion when I responded. Nor do I have a response. Thanks for that, I'll look into it.

LD

Then cool down and understand what is being proposed before demanding for things....

It helps when we talk about the same things ..

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Because then you have ONE function per menu item call... again, what are functions for? They are there so we can make efficient modular use of them, otherwise why use functions at all - we may as just well go back to 2.64

What if I have a 2000 line function called "myBackup" and in the menu item I want "backup now", "backup in 10 minutes" and "backup in an hour"? Do I now need 6000 lines of code? Why? The 2000 lines is all I need, running slightly different based on a parameter it accepts

func myBackup($when) ...

How you are proposing it, I would need a WHOLE other function with its own $when for each item.

LD

Just like this:

$MenuItem_1 = GUICtrlCreateMenuItem("Backup Now", $MenuID)
GUICtrlSetOnEvent(-1, "_MyBackup")
$MenuItem_2 = GUICtrlCreateMenuItem("Backup In 10 minutes", $MenuID)
GUICtrlSetOnEvent(-1, "_MyBackup")
$MenuItem_3 = GUICtrlCreateMenuItem("Backup In one hour", $MenuID)
GUICtrlSetOnEvent(-1, "_MyBackup")

Func _MyBackup()
    Local $Delay
    Switch @GUI_CtrlId
        Case $MenuItem_1
            $Delay = 0 ; Now
        Case $MenuItem_2
            $Delay = 10 * 60 * 1000 ; 10min
        Case $MenuItem_3
            $Delay = 60 * 60 * 1000 ; 1hr
    EndSwitch
    ; ...the rest of _MyBackup()
EndFunc   ;==>_MyBackup

Wasn't that hard, was it?

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Then cool down and understand what is being proposed before demanding for things....

It helps when we talk about the same things ..

:D

No, you're right... and I'm glad this FINALLY got resolved (your suggestion works perfectly, and I thank you for that. It is a work-around though, and still not intuitive and I believe the originally proposed method offers more continuity in process). But still, this took MONTHS to get that suggestion. Prior to that, it was just "no, it doesn't work that way". Still, I guess I didn't have my wheaties today and I apologize for being bitchy. This question was asked and dismissed before, and I went looking for it again and presumed it would be ignored again. It wasn't. Thank you.

Just like this:

$MenuItem_1 = GUICtrlCreateMenuItem("Backup Now", $MenuID)
GUICtrlSetOnEvent(-1, "_MyBackup")
$MenuItem_2 = GUICtrlCreateMenuItem("Backup In 10 minutes", $MenuID)
GUICtrlSetOnEvent(-1, "_MyBackup")
$MenuItem_3 = GUICtrlCreateMenuItem("Backup In one hour", $MenuID)
GUICtrlSetOnEvent(-1, "_MyBackup")

Func _MyBackup()
    Local $Delay
    Switch @GUI_CtrlId
        Case $MenuItem_1
            $Delay = 0 ; Now
        Case $MenuItem_2
            $Delay = 10 * 60 * 1000 ; 10min
        Case $MenuItem_3
            $Delay = 60 * 60 * 1000 ; 1hr
    EndSwitch
    ; ...the rest of _MyBackup()
EndFunc   ;==>_MyBackup

Wasn't that hard, was it?

:)

No, now that we had Jdeb's suggestion (that you put in a GUI context) its not hard at all. But that's not what you were originally suggesting. Or at least it didn't read that way.

LD

Link to comment
Share on other sites

  • Developers

....Still, I guess I didn't have my wheaties today and I apologize for being bitchy....

Have no issue with that and understand you can get frustrated at times when you have the feeling not being heard...

:)

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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