Page 1 sur 1
[R] Clignotement multiple d'images
Posté : mer. 16 févr. 2011 12:38
par pierrotm777
Bonjour,
J'ai besoin dans en script de quatre indicateur qui clignotent si une condition existe.
Voici donc mon example où la condition est ici le check d'une 'checkbox' .
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
$GUI = GUICreate ("test", 130, 130)
$pic1 = GUICtrlCreatePic ("close.jpg", 100, 10, 10, 20)
$pic2 = GUICtrlCreatePic ("close.jpg", 100, 40, 10, 20)
$pic3 = GUICtrlCreatePic ("close.jpg", 100, 70, 10, 20)
$pic4 = GUICtrlCreatePic ("close.jpg", 100, 100, 10, 20)
$AutoUpdate1 = GUICtrlCreateCheckbox("Test1", 10, 10, 90, 17)
$AutoUpdate2 = GUICtrlCreateCheckbox("Test2", 10, 40, 90, 17)
$AutoUpdate3 = GUICtrlCreateCheckbox("Test3", 10, 70, 90, 17)
$AutoUpdate4 = GUICtrlCreateCheckbox("Test4", 10, 100, 90, 17)
GUISetState ()
$blink = False
$timer = TimerInit ()
While 1
$nMsg = GUIGetMsg ()
Switch $nMsg
Case - 3
Exit
EndSwitch
If _IsChecked($AutoUpdate1) Then clignote($Pic1,True)
If _IsChecked($AutoUpdate2) Then clignote($Pic2,True)
If _IsChecked($AutoUpdate3) Then clignote($Pic3,True)
If _IsChecked($AutoUpdate4) Then clignote($Pic4,True)
Wend
Func _IsChecked($control)
Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc ;==>_IsChecked
Func clignote($pic,$blink)
If TimerDiff($timer) >= 1000 Then;1 Second
$timer = TimerInit()
$blink = True
;Switch image
GUICtrlSetImage ($pic, "close.jpg")
ElseIf ($blink = True) And (TimerDiff($timer) >= 100) Then
;Switch Image Back
GUICtrlSetImage ($pic, "open.jpg")
$blink = False
EndIf
EndFunc
Mon problème, c'est que tant qu'un ckeck est actif le clignotement est bien actif.
Mais, si plus d'un checkbox est actif , là c'est le bazard !
De plus , si je décheck un checkbox , l'image reste on et non off .
Merci de votre aide par avance !
Re: [..] Clignotement multiple d'images
Posté : mer. 16 févr. 2011 14:29
par zeshrek
sujet similaire évoqué il y a qq temps.
j'avais mis un script en exemple que tu devrais pouvoir adapter sans trop de probleme
Sujet: [R] Timer.tick ??!
Re: [..] Clignotement multiple d'images
Posté : mer. 16 févr. 2011 14:50
par TommyDDR
Désolé, pas trop le temps d'expliquer le code.
Juste quelques points :
Code : Tout sélectionner
Opt("GUIOnEventMode", 1) ;Passe en mode évenementiel (beaucoup plus claire à mon goût)
avec cela vous pouvez utiliser :
Permettant d'associer des fonction à des actions (au lieu d'avoir un "BIG while(true)"
Et :
A chaque fois que vous nomez vos variables avec un chiffre à la fin, c'est que vous devez passer par un tableau (beaucoup plus simple, sinon il faut gérer tous les cas de nom de variable) avec un tableau, une boucle for permet de parcourir toutes vos variables.
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Dim $Gui
Dim $Pic[4]
Dim $AutoUpdate[4]
Dim $Timer
Dim $VitesseClignotement = 500
$GUI = GUICreate ("test", 130, 130)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
$Pic[0] = GUICtrlCreatePic ("close.jpg", 100, 10, 10, 20)
$Pic[1] = GUICtrlCreatePic ("close.jpg", 100, 40, 10, 20)
$Pic[2] = GUICtrlCreatePic ("close.jpg", 100, 70, 10, 20)
$Pic[3] = GUICtrlCreatePic ("close.jpg", 100, 100, 10, 20)
$AutoUpdate[0] = GUICtrlCreateCheckbox("Test1", 10, 10, 90, 17)
$AutoUpdate[1] = GUICtrlCreateCheckbox("Test2", 10, 40, 90, 17)
$AutoUpdate[2] = GUICtrlCreateCheckbox("Test3", 10, 70, 90, 17)
$AutoUpdate[3] = GUICtrlCreateCheckbox("Test4", 10, 100, 90, 17)
AdlibRegister("Clignote", 100)
For $i = 0 To 3
GUICtrlSetOnEvent($AutoUpdate[$i], "StartStopClignote")
Next
GUISetState ()
$Timer = TimerInit()
While(True)
Sleep(10)
Wend
Func _IsChecked($control)
Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc ;==>_IsChecked
Func StartStopClignote()
Local $NumeroCheck = -1
For $i = 0 To 3
If($AutoUpdate[$i] = @GUI_CtrlId) Then
If(Not(IsChecked($AutoUpdate[$i]))) Then
GUICtrlSetImage($Pic[$i], "close.jpg")
EndIf
ExitLoop
EndIf
Next
EndFunc
Func Clignote()
For $i = 0 To 3
If(IsChecked($AutoUpdate[$i])) Then
If(Mod(TimerDiff($Timer), 2*$VitesseClignotement) < $VitesseClignotement) Then
GUICtrlSetImage($Pic[$i], "open.JPG")
Else
GUICtrlSetImage($Pic[$i], "close.JPG")
EndIf
If(TimerDiff($Timer) > 2*$VitesseClignotement) Then
$Timer = TimerInit()
EndIf
EndIf
Next
EndFunc
Func IsChecked($CtrlID)
Local $Retour = False
If(BitAND(GUICtrlRead($CtrlID), $GUI_CHECKED)) Then
$Retour = True
EndIf
Return $Retour
EndFunc
Func quit()
Exit
EndFunc
Re: [..] Clignotement multiple d'images
Posté : jeu. 17 févr. 2011 13:04
par pierrotm777
Merci à vous deux .
Merci Tommy