Mon Chrono
Publié : lun. 15/oct./2007 17:25
salut à tous !
Code : Tout sélectionner
;################################ ***** ***** ***** **** ***** ** * ***** ** **
;# Programme: Mon Chono # ** ** * ** * ** ** ** * * * ** * ** * **
;# Auteur : SpaceMan/Micko # ***** ***** ***** ** ***** ** * * ***** ** * **
;# Démo : Non # ** ** ** * ** ** ** * ** * ** ***
;# démarré le 12 Octobre 2007 # ***** ** ** * **** ***** ** * ** * ** **
;################################
;je me suis amusé à faire un petit chrono la derniere ou j'ai été coupé du réseau mondial
; ouais c'est grave je sais mais j'en ai profiter pour écrire ce ptit programme et la
;meilleure c'est que j'ai même fait une CallBack ;-)
Declare.s jour_semaine()
Enumeration
#Window_0
EndEnumeration
Enumeration
#StatusBar_Window_0
EndEnumeration
Enumeration
#Calendar_0
#String_2
#Text_3
#Text_4
#String_7
#String_8
#Button_9
#Button_10
#Button_11
#Text_11
#Text_12
#Text_13
#Text_14
#CheckBox_12
EndEnumeration
Enumeration
#Font_String_2
#Font_Text_3
#Font_Text_4
#Font_String_7
#Font_String_8
#Font_Text_11
#Font_Text_12
#Font_Text_13
#Font_Text_14
#Film
EndEnumeration
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
Global StatusBar.l, date,DateText$,ValJour,jour$
Procedure WinCallback(WindowID, Message, wParam, lParam)
Result.l = #PB_ProcessPureBasicEvents
If Message = #WM_SIZE
Select wParam
Case #SIZE_MINIMIZED:
MessageRequester("Mon chrono","Mon Chrono fonctionne! n'ayez aucune crainte",0)
Case #SIZE_RESTORED:
MessageRequester("Mon Chrono","Mon Chrono fonctionne toujours je vous l'avais !",0)
EndSelect
EndIf
ProcedureReturn Result
EndProcedure
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 506, 147, 178, 320, "Mon Chono", #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
; | SetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
; |la fonction ci-dessus fait partie des API et permet de donner une petite hauteur à la barre
; | de titre avec un seul bouton pour la (Fermeture) de la fenêtre
If CreateGadgetList(WindowID(#Window_0))
CalendarGadget(#Calendar_0, 1, 1, 175, 155)
TextGadget(#Text_3, 40, 170, 105, 15, "Date sélectionnée")
TextGadget(#Text_4, 44, 222, 89, 15, "Heure d'alarme")
StringGadget(#String_2, 5, 240, 30, 25, "",#PB_String_Numeric)
StringGadget(#String_7, 68, 240, 30, 25, "",#PB_String_Numeric)
StringGadget(#String_8, 132, 240, 30, 25, "",#PB_String_Numeric)
SendMessage_(GadgetID(#String_2), #EM_LIMITTEXT, 2, 0);envoie un message pour limiter le nombre à 2 chiffres
SendMessage_(GadgetID(#String_7), #EM_LIMITTEXT, 2, 0);pareil
SendMessage_(GadgetID(#String_8), #EM_LIMITTEXT, 2, 0);pareil
ButtonGadget(#Button_9, 1, 281, 50, 18, "Lancer")
ButtonGadget(#Button_10, 126, 281, 51, 18, "Arreter")
ButtonGadget(#Button_11, 63, 281, 51, 18, "Pause",#PB_Button_Toggle)
TextGadget(#Text_11, 9, 185, 160, 25, "Un texte pas tres long", #PB_Text_Border|#PB_Text_Center)
TextGadget(#Text_12, 36, 242, 15, 25, "H")
TextGadget(#Text_13, 100, 242, 16, 25, "M")
TextGadget(#Text_14, 165, 242, 15, 25, "S")
SetGadgetText(#Text_11,jour_semaine()+" "+DateText$) ;permet d'afficher la date du jour ou celle sélectionnée dans le texte gadget
SetGadgetFont(#String_2, LoadFont(#Font_String_2, "Arial", 11, 256))
SetGadgetFont(#Text_3, LoadFont(#Font_Text_3, "Arial", 8, 256))
SetGadgetFont(#Text_4, LoadFont(#Font_Text_4, "Arial", 8, 256))
SetGadgetFont(#String_7, LoadFont(#Font_String_7, "Arial", 11, 256))
SetGadgetFont(#String_8, LoadFont(#Font_String_8, "Arial", 11, 256))
SetGadgetFont(#Text_11, LoadFont(#Font_Text_11, "Arial", 10, 256))
SetGadgetFont(#Text_12, LoadFont(#Font_Text_12, "Arial", 14, 256))
SetGadgetFont(#Text_13, LoadFont(#Font_Text_13, "Arial", 14, 256))
SetGadgetFont(#Text_14, LoadFont(#Font_Text_14, "Arial", 14, 256))
SetGadgetFont(#String_2, LoadFont(#Font_String_2, "Arial", 14, 256))
SetGadgetFont(#String_7, LoadFont(#Font_String_7, "Arial", 14, 256))
SetGadgetFont(#String_8, LoadFont(#Font_String_8, "Arial", 14, 256))
SetGadgetColor(#Text_3,#PB_Gadget_FrontColor,RGB($0,$0,$DF))
SetGadgetColor(#Text_4,#PB_Gadget_FrontColor,RGB($FF,$0,$0))
SetGadgetColor(#String_2,#PB_Gadget_FrontColor,RGB($FF,$0,$0))
SetGadgetColor(#String_7,#PB_Gadget_FrontColor,RGB($FF,$0,$0))
SetGadgetColor(#String_8,#PB_Gadget_FrontColor,RGB($FF,$0,$0))
EndIf
StatusBar = CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0))
AddStatusBarField(90)
AddStatusBarField(90)
StatusBarText(#StatusBar_Window_0, 1, FormatDate("%hh:%ii:%ss", Date()), #PB_StatusBar_Center)
If CreateGadgetList(StatusBarID(#StatusBar_Window_0))
CheckBoxGadget(#CheckBox_12,98, 3, 98, 16, "Réduire-moi")
EndIf
EndIf
EndProcedure
;ma procédure pour récupérer le jour de la semaine
Procedure.s jour_semaine()
date = GetGadgetState(#Calendar_0)
DateText$ = FormatDate("%dd/%mm/%yyyy",date)
ValJour = DayOfWeek(date)
If ValJour = 0
jour$ = "Dimanche"
ElseIf ValJour = 1
jour$ = "Lundi"
ElseIf ValJour = 2
jour$ = "Mardi"
ElseIf ValJour = 3
jour$ = "Mercredi"
ElseIf ValJour = 4
jour$ = "Jeudi"
ElseIf ValJour = 5
jour$ = "Vendredi"
ElseIf ValJour = 6
jour$ = "Samedi"
EndIf
ProcedureReturn jour$
EndProcedure
Procedure jouer_Son() ;cette musique signale à l'utilisateur que son compte à rebours est à 0
NomFichier$ = "E:\Musique\ZOUK\Bela - Destino.mp3" ;changer le chemin par le votre
InitMovie()
LoadMovie(#Film, NomFichier$)
PlayMovie(#Film, WindowID(#Window_0))
EndProcedure
OpenWindow_Window_0() ;ouvre la fenetre mais elle est invisible
ShowWindow_(WindowID(#Window_0), #SW_SHOW);permet d'afficher la fenêtre qui au départ était invisible
SetWindowCallback(@WinCallback()); pour recuperer et gérer les évèments de l'application
Repeat
If Event = #WM_TIMER
;Décompte
sec - 1
If sec < 0
min - 1
sec = 59
If min < 0
Heure - 1
min = 59
SetGadgetText(#String_2, Str(Heure)) ; Affichages des heures
EndIf
SetGadgetText(#String_7, Str(min)) ; Affichage des minutes
EndIf
SetGadgetText(#String_8, Str(sec)) ; Affichage des secondes
If Heure = 0 And min = 0 And sec =0
MessageBeep_(#MB_ICONINFORMATION)
jouer_Son()
Delay(10000) ;joue la musique pendant 10 secondes
End ;puis arrete le programme
EndIf
EndIf
If StatusBar
FormatHeure$ = FormatDate("%hh:%ii:%ss", Date()) ;format de l'heure à utiliser
If Heure$ <> FormatHeure$
Heure$ = FormatHeure$
StatusBarText(#StatusBar_Window_0, 0, Heure$, #PB_StatusBar_Center);affiche l'heure dans la barre de statue
EndIf
EndIf
;pourquoi ici ?
; parceque le gadget appartient à la barre de statue et non directement à la fenetre
If GetGadgetState(#CheckBox_12) = 1: SetWindowState(#Window_0,#PB_Window_Minimize)
SetGadgetState(#CheckBox_12,0)
EndIf
Event = WindowEvent()
Select Event
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Calendar_0
If EventType() = #PB_EventType_LeftDoubleClick : EndIf
SetGadgetText(#Text_11,jour_semaine()+" "+DateText$)
ElseIf EventGadget = #String_2
ElseIf EventGadget = #Text_3
ElseIf EventGadget = #Text_4
ElseIf EventGadget = #String_7
ElseIf EventGadget = #String_8
ElseIf EventGadget = #Button_9 ;bouton lancer
Timer = SetTimer_(WindowID(#Window_0), 0,1000, 0)
Heure = Val(GetGadgetText(#String_2))
min = Val(GetGadgetText(#String_7))
sec = Val(GetGadgetText(#String_8))
ElseIf EventGadget = #Button_11 ; Pause
If KillTimer_(WindowID(#Window_0), 0)
Timer = 0
Else
Timer = SetTimer_(WindowID(#Window_0), 0,1000, 0)
Heure = Val(GetGadgetText(#String_2))
min = Val(GetGadgetText(#String_7))
sec = Val(GetGadgetText(#String_8))
EndIf
ElseIf EventGadget = #Button_10 ; arreter
KillTimer_(WindowID(#Window_0), 0)
;Timer = 0
SetGadgetText(#String_2,"00")
SetGadgetText(#String_7,"00")
SetGadgetText(#String_8,"00") ;:If IsMovie(#Film):StopMovie(#Film):Else:EndIf
ElseIf EventGadget = #Text_11
ElseIf EventGadget = #Text_12
ElseIf EventGadget = #Text_13
ElseIf EventGadget = #Text_14
ElseIf EventGadget = #CheckBox_12
EndIf
Case #PB_Event_CloseWindow
;EventWindow = EventWindow()
;If EventType() = #PB_EventType_LeftDoubleClick : EndIf
;SetWindowState(#Window_0,#PB_Window_Normal)
If EventWindow = #Window_0
CloseWindow(#Window_0);:If IsMovie(#Film):StopMovie(#Film):EndIf
Break
EndIf
EndSelect
ForEver