Jump to content

[SOLVED] Help to create a "TrayItemSetOnEvent" with variables past on to function.


Recommended Posts

Im writeing a script that creates a Traymenu.

one of the features with it is that it download a inifile (.dat) from a site with values Program, Installpath, varibles and so on.

my problem is when i try to create a dynamic list of

"TrayCreateItem($prog[$i][0], $kundprog)"

and trying to set

"TrayItemSetOnEvent($tempprg, _runme($sections[$i],$prog[$i][2],$prog[$i][5]))"

is it possible to send vars to the function?

cant figure out how to make it work....

anyone have a tip?

//Regards Lasse

PS.

Belov function allways run when scrip runs..

iff i add '_runme[vars]' i get error

and if i run 'runme' i lose the vars..

Func _LoadKundSoftData()
local $sections = IniReadSectionNames ( @TempDir &"\CHSofT_" & @OSArch &".dat")
TrayItemDelete($kundprog)
Global $kundprog = TrayCreateMenu("Program",$Instapp)
global $prog[1][7]

For $i = 1 To $sections[0]
; If @error <> 0 Then ExitLoop
IniReadSection(@TempDir &"\CHSofT_" & @OSArch &".dat",$sections[$i])
ReDim $prog[UBound($prog) + 1][8]
$prog[$i][0] = $sections[$i]
$prog[$i][1] = IniRead(@TempDir &"\CHSofT_" & @OSArch &".dat", $sections[$i], 'version', 'Error reading file')
$prog[$i][2] = IniRead(@TempDir &"\CHSofT_" & @OSArch &".dat", $sections[$i], 'setup', 'Error reading file')
$prog[$i][3] = IniRead(@TempDir &"\CHSofT_" & @OSArch &".dat", $sections[$i], 'User', 'Error reading file')
$prog[$i][4] = IniRead(@TempDir &"\CHSofT_" & @OSArch &".dat", $sections[$i], 'Password', 'Error reading file')
$prog[$i][5] = IniRead(@TempDir &"\CHSofT_" & @OSArch &".dat", $sections[$i], 'MSI', 'Error reading file')
$prog[$i][6] = IniRead(@TempDir &"\CHSofT_" & @OSArch &".dat", $sections[$i], 'filesize', 'Error reading file')
$prog[$i][7] = IniRead(@TempDir &"\CHSofT_" & @OSArch &".dat", $sections[$i], 'filetime', 'Error reading file')
_DebugOut("$prog$i : "& $sections[$i])
Global $sections[$i]
Global $tempprg = TrayCreateItem($prog[$i][0], $kundprog)
TrayItemSetOnEvent($tempprg, _runme($sections[$i],$prog[$i][2],$prog[$i][5]))

Next
;_ArrayDisplay($prog)
FileDelete(@TempDir &"\CHSofT_" & @OSArch &".dat")
Return
EndFunc


Func _runme($tp1,$tp2,$tp3)
_DebugOut("$temprunName: "&$tp1)

;shellexecute($temprun[$r][2],"$temprun[$r][5]","","open","")
EndFunc
Edited by lgvlgv
Link to comment
Share on other sites

"TrayItemSetOnEvent($tempprg, _runme($sections[$i],$prog[$i][2],$prog[$i][5]))"

is it possible to send vars to the function?

cant figure out how to make it work....

*SetOnEvent() functions are always empty. You need to deliver your infromation another way.

iff i add '_runme[vars]' i get error

1. use ( and ) to call functions

2. if you define a function with 1 parameter, pass 1 parameter OR use default values

See the helpfile section for functions.

Edited by hannes08
Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

1. use ( and ) to call functions

2. if you define a function with 1 parameter, pass 1 parameter OR use default values

See the helpfile section for functions.

sorry its a typ error i use () but if i use it like this

TrayItemSetOnEvent($tempprg, _runme($sections[$i],$prog[$i][2],$prog[$i][5]))

the _runme executes right away and if i put the '' like this TrayItemSetOnEvent($tempprg, '_runme($sections[$i],$prog[$i][2],$prog[$i][5])')

i get error

Could u point me in how to deliver it in another way any ideas?

both

TrayCreateItem($prog[$i][0], $kundprog)

TrayItemSetOnEvent($tempprg, '_runme') '_runme' should be/contain a variable pointing to diffrent dynamic function depending on privius value of $prog[$i][0]

Edited by lgvlgv
Link to comment
Share on other sites

OnEvent functions can not be called with any parameters. The functions themselves can not have any parameters in the declaration of the function. For example, TrayItemSetOnEvent($tempprg, '_runme') will work as long as the function _runme doesn't have any parameters (Func _runme()). If it does have parameters you're going to get errors on both calling it, and executing the function, you need to use another function that calls the _runme function with the correct parameters in the OnEvent trigger.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

OnEvent functions can not be called with any parameters. The functions themselves can not have any parameters in the declaration of the function. For example, TrayItemSetOnEvent($tempprg, '_runme') will work as long as the function _runme doesn't have any parameters (Func _runme()). If it does have parameters you're going to get errors on both calling it, and executing the function, you need to use another function that calls the _runme function with the correct parameters in the OnEvent trigger.

Thx for verify, thats what i figure.

Any idea witch way i would procced?

maybe put the execution in the While 1 loop and look for "checked" flag on the trayicon, but then i need to loop the try icon some how to find all dynamic created tray "TrayCreateItem($prog[$i][0], $kundprog)", and i have no idea how to do that?

maybe i can use the global $prog array and loop trough that to find the trayitems, what u think?

even better i put it ofcourse in the '_runme' :)

Edited by lgvlgv
Link to comment
Share on other sites

Ok, i come this far..

Now how can i convert "$prog[$i][0]" to a varible or make so that TrayItemGetState/TrayItemSetState can read it and understand?

$prog[$i][0] = "NovellClient"

Any help is much appreciated

//Lasse

Func _runme()
_DebugOut("*******************************************************")
Local $aNewArray = _ArrayUnique($prog)
For $i = 1 to $aNewArray[0]
Local $tmptray=TrayItemGetState($prog[$i][0])
if $tmptray Then
TrayItemSetState($prog[$i][0], $TRAY_UNCHECKED)
exitloop
Else
_DebugOut("Failed EXECUTE: " & $tmptray)
EndIf
Next
Return
;shellexecute($temprun[$r][2],"$temprun[$r][5]","","open","")
EndFunc
Edited by lgvlgv
Link to comment
Share on other sites

What I do is call the function without args, use a Switch on the text of the Tray Item. This is apparently $prog[$i][0] in your code.

So your:

TrayItemSetOnEvent($tempprg, _runme($sections[$i],$prog[$i][2],$prog[$i][5]))

Would look like

TrayItemSetOnEvent($tempprg, "_runme")

Then the _runme() would contain a Switch with cases that depend on the the string defined by:

$sections[$i],$prog[$i][2],$prog[$i][5])

This also has the added advantage that you don't have to pre-read anything from the ini except the $sections. Wait till the function is called to read the section values and run $sections[$i],$prog[$i][2],$prog[$i][5] based on the return there.

Link to comment
Share on other sites

What I do is call the function without args, use a Switch on the text of the Tray Item. This is apparently $prog[$i][0] in your code.

So your:

TrayItemSetOnEvent($tempprg, _runme($sections[$i],$prog[$i][2],$prog[$i][5]))

Would look like

TrayItemSetOnEvent($tempprg, "_runme")

Then the _runme() would contain a Switch with cases that depend on the the string defined by:

$sections[$i],$prog[$i][2],$prog[$i][5])

This also has the added advantage that you don't have to pre-read anything from the ini except the $sections. Wait till the function is called to read the section values and run $sections[$i],$prog[$i][2],$prog[$i][5] based on the return there.

hmm, will it work regarding that the switch in that case also need to be dynamic? the "case" could be anything from 1 to +50 dependig how many sections i have in the inifile that is downloaded from website.
Link to comment
Share on other sites

Yes, I have written a complete open with replacement shell for windows this way, that would give a unique drawer of choices for every filetype and act as a drawer of options for every link toolbar link. Presently doing a rewrite so that configuring it doesn't require manually editing the config file. All files are associated with the same AutoIt program on my windows machine.

Link to comment
Share on other sites

Yes, I have written a complete open with replacement shell for windows this way, that would give a unique drawer of choices for every filetype and act as a drawer of options for every link toolbar link. Presently doing a rewrite so that configuring it doesn't require manually editing the config file. All files are associated with the same AutoIt program on my windows machine.

Im sorry, u lost me after " I have written a complete " :)

do u have some example i can study?

/Regards Lasse

:)

Link to comment
Share on other sites

I don't really get what exactly you cod is supposed to act on, but I used a fluffed ini with the contents:

[App1]
version=version 0.1
setup=setup true
User=Username
Password=mypass
MSI=install.msi
filesize=6.2 meg
filetime=1952
[app2]
version=version 0.2
setup=setup true
User=Username2
Password=anotherpass
MSI=install.msi
filesize=8.1 meg
filetime=1958

The sample code:

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode",1)

local $sections = IniReadSectionNames(@ScriptDir &"\CHSofT.ini")
For $i = 1 To $sections[0]
TrayCreateItem($sections[$i])
TrayItemSetOnEvent(-1,"_runme")
Next
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"_runme")

While 1
Sleep(50)
WEnd

Func _runme()
$sect=TrayItemGetText(@TRAY_ID)
If $sect="Exit" Then Exit
$prog1=IniRead(@ScriptDir &"\CHSofT.ini", $sect, 'setup', 'Error reading file')
$prog2=IniRead(@ScriptDir &"\CHSofT.ini", $sect, 'MSI', 'Error reading file')
;~ _runme($sect,$prog1,$prog1) is the equivalent of _runme($sections[$i],$prog[$i][2],$prog[$i][5]))
;~ Though you can do you function stuff here now and retrive anything from the ini under $sect.
MsgBox(0,"",$sect &" | "& $prog1 & " | "& $prog2)
EndFunc
Link to comment
Share on other sites

Wonderful!!

Ur great that @TRAY_ID is a killer, dident know about that one....

here are my compleate code "software code", it works great.

Im going to put this threed in "solved" (i just figure out to do that to :) )

Func _CheckKundSoftware()
InetClose($i_InetGetHandle)
$i_InetGetHandle=-1
if @OSArch = "X86" Then
_DebugOut('(_CheckKundSoftware) Architecture: '& @OSArch)
$i_InetGetHandle = InetGet($s_CHSofT_x86, @TempDir &"CHSofT_x86.dat", 3, 1)
ToolTip("Starting to update")
Do
; _DebugOut('Downloading update '&'CHSofT_x86.dat'&" <- " &InetGetInfo($i_InetGetHandle, 0))
Until InetGetInfo($i_InetGetHandle, 2)

If @error <> 0 Then
_DebugOut('Could not connect to site, Please check your connection and try again')
EndIf
InetClose($i_InetGetHandle)
TrayItemSetState($checksoftupdate, $TRAY_UNCHECKED)
_LoadKundSoftData()
ElseIf @OSArch = "X64" Then
_DebugOut('(CheckKundSoftware) Architecture: '& @OSArch)
$i_InetGetHandle = InetGet($s_CHSofT_x64, @TempDir &"CHSofT_x64.dat", 3, 1)
Do
_DebugOut('Downloading update '&'CHSofT_x64.dat'& " <- " &InetGetInfo($i_InetGetHandle, 0))
Until InetGetInfo($i_InetGetHandle, 2)
If @error <> 0 Then
_DebugOut('Could not connect to site, Please check your connection and try again')
EndIf
InetClose($i_InetGetHandle)
TrayItemSetState($checksoftupdate, $TRAY_UNCHECKED)
_LoadKundSoftData()
Else
_DebugOut('(CheckKundSoftware) Not a valid architecture: '& @OSArch)
EndIf

EndFunc

Func _LoadKundSoftData()
global $prog[1][7]
TrayItemDelete($kundprog)
Global $kundprog = TrayCreateMenu(RegRead($key7 & "SOFTWAREChargeChargeDeamon", "Kund")&"-Program",$Instapp)
_DebugOut('Inside _LoadKundSoftData')
local $sections = IniReadSectionNames ( @TempDir &"CHSofT_" & @OSArch &".dat")
For $i = 1 To $sections[0]
TrayCreateItem($sections[$i], $kundprog)
TrayItemSetOnEvent(-1,"_runme")
Next
TrayItemSetOnEvent(-1,"_runme")
EndFunc

Func _runme()
Global $prog[1][7]
Local $prog1,$prog2
_DebugOut("*******************************************************")
Global $sections = IniReadSectionNames ( @TempDir &"CHSofT_" & @OSArch &".dat")

$sect=TrayItemGetText(@TRAY_ID)
If $sect="Exit" Then Exit
For $i = 1 To $sections[0]
ReDim $prog[UBound($prog) + 1][8]
$prog[$i][0] = $sections[$i]
$prog[$i][1] = IniRead(@TempDir &"CHSofT_" & @OSArch &".dat", $sect, 'version', 'Error reading file')
$prog[$i][2] = IniRead(@TempDir &"CHSofT_" & @OSArch &".dat", $sect, 'setup', 'Error reading file')
$prog[$i][3] = IniRead(@TempDir &"CHSofT_" & @OSArch &".dat", $sect, 'User', 'Error reading file')
$prog[$i][4] = IniRead(@TempDir &"CHSofT_" & @OSArch &".dat", $sect, 'Password', 'Error reading file')
$prog[$i][5] = IniRead(@TempDir &"CHSofT_" & @OSArch &".dat", $sect, 'MSI', 'Error reading file')
$prog[$i][6] = IniRead(@TempDir &"CHSofT_" & @OSArch &".dat", $sect, 'filesize', 'Error reading file')
$prog[$i][7] = IniRead(@TempDir &"CHSofT_" & @OSArch &".dat", $sect, 'filetime', 'Error reading file')

$prog1=$prog[$i][2]
$prog2=$prog[$i][5]
Next
MsgBox(0,"",$sect &" | "& $prog1 & " | "& $prog2)
$sect=TrayItemSetState(@TRAY_ID, $TRAY_UNCHECKED)
EndFunc
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...