Page 1 sur 1
[R] Fonctions et parametres
Posté : mer. 10 sept. 2008 17:18
par linvi
Voilà, j'aimerais appeler une fonction possédant un paramètre en utilisant, un Set_On_Event.
Je n'ai pas trouver ni dans l'aide ni sur le forum une manière de réaliser cela.
Voici mon code:
Code : Tout sélectionner
TrayCreateItem("Quitter")
TrayItemSetOnEvent(-1, "Finish 5")
Func Finish($ShutValue)
J'aimerais définir la valeur de $ShutValue à 5
Merci de votre aide
Re: [..] Fonctions et parametres
Posté : mer. 10 sept. 2008 19:15
par jbnh
mhh, j'ai pas bien compris.
Peut être :
Re: [..] Fonctions et parametres
Posté : mer. 10 sept. 2008 19:30
par timmalos
Regardez l'exemple ecrit dans la fonction GUICtrlSetOnEvent .
Mais ce n'est pas très pratique.
Je ne vois pas ce que vous souhaitez faire.
Re: [..] Fonctions et parametres
Posté : mer. 10 sept. 2008 20:03
par linvi
@jbnh
Cela ne fonctionne pas, il me met que la fonction n'est pas définie.
En gros, je cherche à passer l'argument 5 à la fonction Finish.
Voici le code complet pour mieux comprendre.
► Afficher le texteCode
Code : Tout sélectionner
Func InitTray()
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
TraySetState()
TraySetClick(8)
TraySetIcon("ATP32.dll", -1)
TrayCreateItem("Resume")
TrayItemSetOnEvent(-1, "Finish")
TrayCreateItem("")
TrayCreateItem("Quitter")
TrayItemSetOnEvent(-1, "Finish(5)")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"_Show")
EndFunc
Func _Show()
GUISetState(@SW_SHOW)
EndFunc
Func Finish($ShutValue)
$OkValue = "End"
If $ShutValue = 0 Then
Run(@ComSpec & " /c " & "rundll32 powrprof.dll,SetSuspendState")
ElseIf $ShutValue = 1 Then
Shutdown(32)
ElseIf $ShutValue = 2 Then
Run(@ComSpec & " /c " & "shutdown -s -f -t 0")
ElseIf $ShutValue = 3 Then
Run(@ComSpec & " /c " & "shutdown -r -f -t 0")
ElseIf $ShutValue = 4 Then
GUICtrlSetData($Ok,"Quitter")
$Src = GUICtrlRead($Input)
If ($Src = "Default") Then
$Src = @TempDir & "\TimerDefault.mp3"
FileInstall("C:\yop.mp3", @TempDir & "\TimerDefault.mp3", 1)
EndIf
$Sound = _SoundOpen($Src,0)
_SoundPlay($Sound)
While 1
Global $nMsg = GUIGetMsg()
If _SoundPos($Sound, 2) = _SoundLength($Sound, 2) Then
_SoundPlay($Sound)
EndIf
Switch $nMsg
Case $Ok
ExitLoop
Case $GUI_EVENT_CLOSE
ExitLoop
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE)
EndSwitch
WEnd
EndIf
FileDelete(@TempDir & "\TimerDefault.mp3")
_SoundClose($Sound)
Exit
EndFunc ;==>Finish
Rapport d'erreur:
C:\Documents and Settings\TimerOff.au3(217,45) : ERROR: Finish($ShutValue)(): undefined function.
TrayItemSetOnEvent(-1, "Finish($ShutValue)")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\TimerOff.au3(220,36) : ERROR: Finish(5)(): undefined function.
TrayItemSetOnEvent(-1, "Finish(5)")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\TimerOff.au3 - 2 error(s), 0 warning(s)
timmalos a écrit :Regardez l'exemple ecrit dans la fonction GUICtrlSetOnEvent .
Dans cet exemple, il n'y a aucune fonction prennant un parametre en argument.
Re: [..] Fonctions et parametres
Posté : mer. 10 sept. 2008 20:52
par timmalos
linvi a écrit :
timmalos a écrit :Regardez l'exemple ecrit dans la fonction GUICtrlSetOnEvent .
Dans cet exemple, il n'y a aucune fonction prennant un parametre en argument.
En effet! En regardant mieux, il y a une partie que je pensais pouvoir vous aider, mais en fait, non
Code : Tout sélectionner
$parent1 = GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
avec
Code : Tout sélectionner
Func SpecialEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
Exit
Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
Case @GUI_CtrlId = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
EndSelect
EndFunc ;==>SpecialEvents
Mais en fait, ca ne vous servira a rien dans ce cas la, mea culpe !

Re: [..] Fonctions et parametres
Posté : mer. 10 sept. 2008 20:56
par timmalos
Par contre :
TrayItemSetOnEvent(-1, "Finish(5)")
En ayant vu votre code, vous pouvez facilement remplacer la ligne ci-dessous par:
TrayItemSetOnEvent(-1, "Finish5")
PUis de rejouter une autre fonction
Func Finish5
finish(5)
EndFunc
Re: [..] Fonctions et parametres
Posté : mer. 10 sept. 2008 22:02
par Tlem
Pourquoi ne déclarez vous pas plutôt la variable avant le
TrayItemSetOnEvent ???
► Afficher le texte
Code : Tout sélectionner
Dim $ShutValue
Func InitTray()
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
TraySetState()
TraySetClick(8)
TraySetIcon("ATP32.dll", -1)
TrayCreateItem("Resume")
TrayItemSetOnEvent(-1, "Finish")
TrayCreateItem("")
If $XXX Then $ShutValue = $Y ; Entrez ici la condition qui donne la valeur à $ShutValue
TrayCreateItem("Quitter")
TrayItemSetOnEvent(-1, "Finish")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"_Show")
EndFunc
Func _Show()
GUISetState(@SW_SHOW)
EndFunc
Func Finish()
$OkValue = "End"
If $ShutValue = 0 Then
Run(@ComSpec & " /c " & "rundll32 powrprof.dll,SetSuspendState")
ElseIf $ShutValue = 1 Then
Shutdown(32)
ElseIf $ShutValue = 2 Then
Run(@ComSpec & " /c " & "shutdown -s -f -t 0")
ElseIf $ShutValue = 3 Then
Run(@ComSpec & " /c " & "shutdown -r -f -t 0")
ElseIf $ShutValue = 4 Then
GUICtrlSetData($Ok,"Quitter")
$Src = GUICtrlRead($Input)
If ($Src = "Default") Then
$Src = @TempDir & "\TimerDefault.mp3"
FileInstall("C:\yop.mp3", @TempDir & "\TimerDefault.mp3", 1)
EndIf
$Sound = _SoundOpen($Src,0)
_SoundPlay($Sound)
While 1
Global $nMsg = GUIGetMsg()
If _SoundPos($Sound, 2) = _SoundLength($Sound, 2) Then
_SoundPlay($Sound)
EndIf
Switch $nMsg
Case $Ok
ExitLoop
Case $GUI_EVENT_CLOSE
ExitLoop
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE)
EndSwitch
WEnd
EndIf
FileDelete(@TempDir & "\TimerDefault.mp3")
_SoundClose($Sound)
Exit
EndFunc ;==>Finish
Re: [..] Fonctions et parametres
Posté : mer. 10 sept. 2008 23:59
par linvi
@timmalos
J'avais déja résolu le problème de la manière que tu viens d'indiquer, mais je trouve ça quand même trés moche.
@Tlem
C'est en réalité le fait de cliquer sur Le TrayItem qui met la valeur à 5. La condition pour envoyer la valeur 5 est le fait de cliquer sur "Quitter" du TrayMenu.
S'il n'y a pas d'autres solution que celle proposée par Timmalos, c'est pas bien grave mais le code est je trouve bien moche...
Re: [..] Fonctions et parametres
Posté : ven. 12 sept. 2008 19:51
par sylvanie
On peut utiliser la macro @Tray_Id pour savoir quel Id du tray a été cliqué.
Ainsi on peut fixer l'argument en fonction de l'id du contrôle cliqué :
► Afficher le texte
Code : Tout sélectionner
#include <Constants.au3>
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
Global $Item_reseume,$Item_Exit
InitTray()
While 1
Sleep(100)
WEnd
Func InitTray()
TraySetState()
TraySetClick(8)
TraySetIcon("ATP32.dll", -1)
$Item_reseume=TrayCreateItem("Resume")
TrayItemSetOnEvent(-1, "Finish")
TrayCreateItem("")
$Item_Exit=TrayCreateItem("Quitter")
TrayItemSetOnEvent(-1, "Finish")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"_Show")
EndFunc
Func _Show()
GUISetState(@SW_SHOW)
EndFunc
Func Finish()
Local $arg,$sortie=0
Switch @TRAY_ID
Case $Item_reseume
$arg="resume pressed"
Case $Item_Exit
$arg="exit pressed"
$sortie=1
EndSwitch
MsgBox(0,"Test", $arg)
If ($sortie) Then Exit 0
EndFunc
Re: [..] Fonctions et parametres
Posté : sam. 13 sept. 2008 00:58
par linvi
Merci beaucoup, je pense que ça va répondre à mon problème.
Je clos le sujet.
Merci pour votre aide.