Enumeration
#fenetre
#rond
#petitrond
#moyenrond
EndEnumeration
Declare.f RotationX(x, angle.f, dist)
Declare.f RotationY(Y, angle.f, dist)
Declare Forme(fenetre,forme)
Declare RemoveFromTaskbar(hwnd)
; *********** initialisation *********
Global rezX=320
Global rezy=240
Global xa=rezy/2
Global ya=rezy/2
Global distance=rezy/2-4
Global degress,degresm,degresh, tops, topm, toph
Structure sprite
x.l
Y.l
vitesse.l
EndStructure
Dim sprite.sprite(1000)
; ******************************
InitMouse ()
InitKeyboard ()
; ******** ** pour le sprite *****************
InitSprite ()
; ***************************************
OpenWindow ( #fenetre , 0,0, rezX, rezy, "Horloge" , #PB_Window_BorderLess ) ; on ouvre une fenetre
Handle= WindowID ( #fenetre )
; Style_etendu=GetWindowLong_(WindowID(#fenetre),#GWL_EXSTYLE)
; SetWindowLong_(WindowID(#fenetre),#GWL_EXSTYLE,Style_etendu|#WS_EX_TOOLWINDOW)
OpenWindowedScreen ( WindowID ( #fenetre ) , 0, 0, rezX, rezy, 0, 0, 0) ; on met un ecran dedans !!
; AddSysTrayIcon(1, WindowID(0), LoadImage(0, "D:\PureBasic\dobro\logo\icone.ico"))
; SysTrayIconToolTip(1, "horloge")
; StickyWindow(#fenetre,1)
RemoveFromTaskbar( FindWindow_ ( #fenetre , "Horloge" )) ; fait disparaitre la fenetre de la barre des taches
For spr=100 To 1000
CreateSprite (spr,2,2)
StartDrawing ( SpriteOutput (spr)) ;
sprite(spr)\x= Random (rezX)
sprite(spr)\Y= Random (rezy)
sprite(spr)\vitesse= Random (3)+1
Circle (1,1,1, RGB ( Random (255), Random (255), Random (255)))
StopDrawing ()
Next spr
Forme ( #fenetre ,2) ; ronde
Repeat ; boucle principale
Event= WindowEvent () ; on regarde si quelqu'un a cliqué sur la croix pour quitter
ExamineMouse () ; on demande a purebasic de surveiller les event de souris !
ExamineKeyboard () ; on demande a purebasic de surveiller les event de clavier!
; *************************
date = Date ()
Heure= Hour (date)
Minute = Minute (date)
Seconde= Second (date)
For spr=100 To 1000
DisplaySprite (spr, sprite(spr)\x, sprite(spr)\Y)
sprite(spr)\Y= sprite(spr)\Y+sprite(spr)\vitesse
If sprite(spr)\Y>rezy: sprite(spr)\Y=1: EndIf
Next spr
If MouseButton (2) Or KeyboardPushed ( #PB_Key_All ) ; le bouton de souris droit fait quitter ! ou bien n'importe quel touche
End
EndIf
If MouseButton (1)
SendMessage_ ( WindowID ( #fenetre ), #WM_NCLBUTTONDOWN , #HTCAPTION , 0)
EndIf
degress=Seconde*6
; Ici, le code à executer toutes les secondes
xs= RotationX(xa, degress-90, distance)
Ys= RotationY(ya, degress-90, distance)
; aiguille des secondes
StartDrawing ( ScreenOutput ())
LineXY (xa, ya, xs, Ys , RGB ($E9,$32,$92)) ; les secondes rouge
StopDrawing ()
; Ici, le code à executer toutes les minutes
degresm = Minute *6
xm= RotationX(xa, degresm-90, distance-25)
Ym= RotationY(ya, degresm-90, distance-25)
; aiguille des minute
StartDrawing ( ScreenOutput ())
LineXY (xa, ya, xm, Ym , RGB ($5,$E2,$B6)) ; les minutes verte
StopDrawing ()
; Ici, le code à executer toutes les heures
degresh =Heure*6*5
xh= RotationX(xa, degresh-90, distance-50)
Yh= RotationY(ya, degresh-90, distance-50)
; aiguille des heures
StartDrawing ( ScreenOutput ())
LineXY (xa, ya, xh, Yh , RGB ($F5,$F9,$6A)) ; les heures jaune
StopDrawing ()
StartDrawing ( ScreenOutput ())
DrawingMode ( #PB_2DDrawing_Transparent )
DrawText (xa- TextWidth ( "By Dobro" )/2, rezy/2-100, "By Dobro" , RGB ($7A,$97,$FC), RGB ($0,$0,$0))
DrawText (ya- TextWidth ( Str (Heure)+ ":" + Str ( Minute )+ ":" + Str (Seconde))/2, rezy/2, Str (Heure)+ ":" + Str ( Minute )+ ":" + Str (Seconde) , RGB ($7A,$97,$FC), RGB ($0,$0,$0))
StopDrawing ()
;{ ****************** dessin de l'horloge **********************
For a=1 To 60
degres =degres+6 : If degres=360:degres=0: EndIf : ; cela fait tourner
x= RotationX(xa, degres, distance)
Y= RotationY(ya, degres, distance)
quart=quart+1
If quart=15
quart=0
StartDrawing ( ScreenOutput ())
Circle (x,Y,8, RGB ($F9,$66,$FD))
StopDrawing ()
EndIf
min=min+1
If min<>15
StartDrawing ( ScreenOutput ())
Circle (x,Y,4, RGB ($75,$66,$FD))
StopDrawing ()
Else
min=0
EndIf
min2=min2+1
If min2=5
StartDrawing ( ScreenOutput ())
Circle (x,Y,4, RGB ($E7,$F0,$39))
StopDrawing ()
min2=0
EndIf
Next a
;} ****************************************************************************
; ***************************************************
FlipBuffers ()
ClearScreen ( RGB (0, 0, 0)) ; <--- c'est la place normale pour le clearscreen !!
Delay (5)
Until Event= #PB_Event_CloseWindow ; boucle temps que l'evenement de fenetre n'est pas #PB_Event_CloseWindow (un appuis sur la croix)
; chose qui ne peut pas arrivé sur ce programme !!
Return
Procedure.f RotationX(x, angle.f, dist)
ProcedureReturn x + Cos (angle.f* #PI /180)*dist
EndProcedure
Procedure.f RotationY(Y, angle.f, dist)
ProcedureReturn Y + Sin (angle.f* #PI /180)*dist
EndProcedure
Procedure Forme(fenetre,forme)
If forme=1 ; si on a choisi la forme 1 Angles arrondis
Region = CreateRoundRectRgn_ (0, 0, WindowWidth (fenetre), WindowHeight (fenetre), 40, 60) ; Création de la région pour faire une fenêtre avec les angles arrondis
; CreateRoundRectRgn_(X1, Y1, X2, Y2, R1, R2)
; X1, Y1 : coordonné du point haut gauche de la region
; X1, Y1 : coordonné du point haut gauche de la region
; R1, R2 : rayon de l'ellipse qui va servir à arrondir les angles de la region
SetWindowRgn_ ( WindowID (fenetre), Region, #True ) ; On applique la région
DeleteObject_ (Region) ; On supprime la région
ElseIf forme=2 ; si on a choisi la forme 2 Ronde
Region = CreateEllipticRgn_ (0, 0, WindowHeight (fenetre), WindowHeight (fenetre)) ; Création de la région pour faire une fenêtre elliptique
; CreateEllipticRgn_(X1, Y1, X2, Y2)
; X1, Y1 : coordonné du point haut gauche de la region
; X1, Y1 : coordonné du point haut gauche de la region
SetWindowRgn_ ( WindowID (fenetre), Region, #True ) ; On applique la région
DeleteObject_ (Region) ; On supprime la région
ElseIf forme=3 ; si on a choisi la forme 3 Triangle
Region = CreatePolygonRgn_ (?Triangle, 4, #ALTERNATE ) ; Création de la région pour faire une fenêtre elliptique
; CreateRoundRectRgn_(Array, NbPoints, Type)
; Array : Adresse de la liste ou de la Data
; NbPoints : Nombre de points du polygone + 1 (car on fait une boucle donc on a 2 fois le premier point)
; Type : Voir msdn
SetWindowRgn_ ( WindowID (fenetre), Region, #True ) ; On applique la région
DeleteObject_ (Region) ; On supprime la région
ElseIf forme=4 ; si on a choisi la forme 4 Trouée
Region1 = CreateRectRgn_ (0, 0, WindowWidth (fenetre), WindowHeight (fenetre)) ; Création d'une région en rectangle
Region2 = CreateRectRgn_ (10, 10, WindowWidth (fenetre) - 10, 50) ; Création d'une région en rectangle
; CreateRectRgn_(X1, Y1, X2, Y2)
; X1, Y1 : coordonné du point haut gauche de la region
; X1, Y1 : coordonné du point haut gauche de la region
CombineRgn_ (Region1, Region1, Region2, #RGN_DIFF ) ; On combine les 2 régions
; Les modes suivants sont disponibles :
; #RGN_AND : Intersection
; #RGN_OR : Union
; #RGN_DIFF : Différences
; #RGN_XOR : Union moins les intersections
SetWindowRgn_ ( WindowID (fenetre), Region1, #True ) ; On applique la région finale
DeleteObject_ (Region1) ; On supprime les régions
DeleteObject_ (Region2)
ElseIf forme=5 ; si on a choisi la forme 5 Triangle + Rond
Region1 = CreatePolygonRgn_ (?Triangle, 4, #ALTERNATE )
Region2 = CreateEllipticRgn_ (0, 0, WindowWidth (fenetre), WindowHeight (fenetre))
CombineRgn_ (Region1, Region1, Region2, #RGN_OR ) ; On combine les 2 régions
SetWindowRgn_ ( WindowID (fenetre), Region1, #True ) ; On applique la région finale
DeleteObject_ (Region1) ; On supprime les régions
DeleteObject_ (Region2)
ElseIf forme=6 ; si on a choisi la forme 2 Ronde troué
Region = CreateEllipticRgn_ (0, 0, WindowHeight (fenetre), WindowHeight (fenetre)) ; Création de la région pour faire une fenêtre elliptique
Region2 = CreateEllipticRgn_ (15, 15, WindowHeight (fenetre)-15, WindowHeight (fenetre)-15) ; Création de la région pour faire une fenêtre elliptique
CombineRgn_ (Region1, Region1, Region2, #RGN_DIFF ) ; On combine les 2 régions
; CreateEllipticRgn_(X1, Y1, X2, Y2)
; X1, Y1 : coordonné du point haut gauche de la region
; X1, Y1 : coordonné du point haut gauche de la region
SetWindowRgn_ ( WindowID (fenetre), Region, #True ) ; On applique la région
DeleteObject_ (Region) ; On supprime la région
DeleteObject_ (Region2)
EndIf
EndProcedure
Procedure RemoveFromTaskbar(hwnd)
If IsWindow_ (hwnd)
a=hwnd : b= GetWindowLong_ (a, #GWL_HWNDPARENT ) : If b<>0 : a=b : EndIf ; Needed for "TaskAssign.exe".
ShowWindow_ (a, #SW_HIDE ) : GetWindowRect_ (a,win.RECT) : w=win\right-win\left : h=win\bottom-win\top
SetWindowLong_ (a, #GWL_EXSTYLE , #WS_EX_TOOLWINDOW ) : SetWindowPos_ (a,0,0,0,w-1,h-1, #SWP_NOMOVE )
SetWindowPos_ (a,0,0,0,w,h, #SWP_NOMOVE|#SWP_SHOWWINDOW ) : ProcedureReturn 1
EndIf
EndProcedure
DataSection
Triangle :
Data.l 200, 400, 0, 0, 400, 0, 200, 400 ; Coordonnées des points du triangle en x, y (il faut faire une boucle donc on revient au premier point du triangle
EndDataSection
Screen Horloge
Screen Horloge
Last edited by dobro on Tue Oct 31, 2006 11:07 am, edited 1 time in total.
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Thanks. A little tweaking and you'll have some competitionnetmaestro wrote:You have to change the Dim line for the sprite array from 900 to 1000, then it will work. Once you get it going, it's got the mouse captured, so you can't do anything else until you close it. It just needs a couple tweaks, but it looks very good! Good work
Now, about them chimes . . .
cheers
it is necessary to click apart from the clock on the desk to be able to make another thing and that a "right click" on the clock finishes the program 

Fixed! Thanknetmaestro wrote:You have to change the Dim line for the sprite array from 900 to 1000, then it will work. Once you get it going, it's got the mouse captured, so you can't do anything else until you close it. It just needs a couple tweaks, but it looks very good! Good work
new Version , no screen , just Windows 
Enumeration
#fenetre
#rond
#petitrond
#moyenrond
#Image
#Text_0
#dobro
EndEnumeration
#CAPTUREBLT = $40000000
Declare.f RotationX(x, angle.f, dist)
Declare.f RotationY(Y, angle.f, dist)
Declare Forme(fenetre,forme)
Declare RemoveFromTaskbar(hwnd)
Declare WindowCallback( WindowID ,message,wParam,lParam)
Declare dessin_horloge()
; *********** initialisation *********
Global rezX=200
Global rezy=200
Global xa=rezy/2
Global ya=rezy/2
Global distance=rezy/2-4
Global Perdu=0 ; defini si l'on perds le focus !!
Global sprite=200
Global degress,degresm,degresh, tops, topm, toph,Pos_wx,Pos_wy, pas,min_col
Global NewList buffer.l ()
Structure sprite2
x.l
Y.l
vitesse.l
couleur_r.l
couleur_v.l
couleur_b.l
EndStructure
Global Dim sprite2.sprite2(sprite)
ExamineDesktops ()
For i=1 To sprite-1
sprite2(i)\x= Random (rezX)+1
sprite2(i)\Y= Random (rezy)+1
sprite2(i)\vitesse= Random (5)+1
sprite2(i)\ couleur_r= Random (255)+50
sprite2(i)\ couleur_v= Random (255)+50
sprite2(i)\ couleur_b= Random (255)+50
Next i
; ; ****************************PHOTO ***************
;
; ; ******************************** on change la taille de la fenetre pour forcer un redraw ************
;
CreateImage ( #Image , DesktopWidth (0), DesktopHeight (0))
dc_bur = GetDC_ (0)
DC_im = StartDrawing ( ImageOutput ( #Image ))
BitBlt_ (DC_im,0,0 , DesktopWidth (0), DesktopHeight (0), dc_bur , 0,0 , #SRCPAINT|#CAPTUREBLT ) ; recup le bureau dans image
StopDrawing ()
ReleaseDC_ (0, dc_bur)
; ********************************************************************************************************************************
If OpenFile (1, "Horloge.ini" )
Pos_wx= Val ( ReadString (1))
Debug Pos_wx
Pos_wy= Val ( ReadString (1))
Debug Pos_wy
CloseFile (1)
EndIf
OpenWindow ( #fenetre , 0,0, rezX, rezy, "Horloge" , #PB_Window_BorderLess ) ; on ouvre une fenetre
Handle= WindowID ( #fenetre )
SetWindowColor ( #fenetre , RGB (0,0,0))
SetWindowCallback (@WindowCallback()) ; un callback pour que le dessin reste sur la fenetre (repaint)
RemoveFromTaskbar( FindWindow_ ( #fenetre , "Horloge" )) ; fait disparaitre la fenetre de la barre des taches
Forme ( #fenetre ,2) ; ronde
ResizeWindow ( #fenetre ,Pos_wx,Pos_wy,rezX,rezy)
Repeat ; boucle principale
;
; *************************
Global date = Date ()
Global Heure= Hour (date)
Global Minute = Minute (date)
Global Seconde= Second (date)
Event= WindowEvent () ; on regarde si quelqu'un a cliqué sur la croix pour quitter
If Event <>0
Debug Event
EndIf
If Event= #WM_MOUSEFIRST Or Event= #PB_Event_ActivateWindow Or Event=49310 ; la souris est sur l'horloge
EndIf
Select Event
Case #WM_LBUTTONDOWN ; deplace fenetre
SendMessage_ ( WindowID ( #fenetre ), #WM_NCLBUTTONDOWN , #HTCAPTION , 0)
Case #WM_RBUTTONDOWN ; click droit sur l'horloge
OpenFile (1, "Horloge.ini" )
WriteStringN (1, Str (Pos_wx))
WriteStringN (1, Str (Pos_wy))
CloseFile (1)
End
EndSelect
If Memsecond<>Seconde
SendMessage_ ( WindowID ( #fenetre ), #dobro , #HTCAPTION , 0) ; chaque seconde on envoi un message #dobro
EndIf
Memsecond=Seconde
degress=Seconde*6
; Ici, le code à executer toutes les secondes
xs= RotationX(xa, degress-90, distance)
Ys= RotationY(ya, degress-90, distance)
; aiguille des secondes
StartDrawing ( WindowOutput ( #fenetre ))
LineXY (xa, ya, xs, Ys , RGB ($E9,$32,$92)) ; les secondes rouge
For i=-2 To 2
LineXY (xa+i, ya+i, xs, Ys , RGB ($E9,$32,$92)) ; les secondes rouge
Next i
StopDrawing ()
; Ici, le code à executer toutes les minutes
degresm = Minute *6
xm= RotationX(xa, degresm-90, distance-25)
Ym= RotationY(ya, degresm-90, distance-25)
; aiguille des minute
StartDrawing ( WindowOutput ( #fenetre ))
LineXY (xa, ya, xm, Ym , RGB ($5,$E2,$B6)) ; les minutes verte
For i=-2 To 2
LineXY (xa+i, ya+i, xm, Ym , RGB ($5,$E2,$B6)) ; les secondes rouge
Next i
StopDrawing ()
; Ici, le code à executer toutes les heures
degresh =Heure*6*5
xh= RotationX(xa, degresh-90, distance-50)
Yh= RotationY(ya, degresh-90, distance-50)
; aiguille des heures
StartDrawing ( WindowOutput ( #fenetre ))
LineXY (xa, ya, xh, Yh , RGB ($F5,$F9,$6A)) ; les heures jaune
For i=-2 To 2
LineXY (xa+i, ya+i, xh, Yh , RGB ($F5,$F9,$6A)) ; les secondes rouge
Next i
StopDrawing ()
dessin_horloge()
; ***************************************************
Delay (2)
ForEver ;
Return
Procedure.f RotationX(x, angle.f, dist)
ProcedureReturn x + Cos (angle.f* #PI /180)*dist
EndProcedure
Procedure.f RotationY(Y, angle.f, dist)
ProcedureReturn Y + Sin (angle.f* #PI /180)*dist
EndProcedure
Procedure Forme(fenetre,forme)
If forme=2 ; si on a choisi la forme 2 Ronde
Region = CreateEllipticRgn_ ( 0, 0, WindowHeight (fenetre), WindowHeight (fenetre)) ; Création de la région pour faire une fenêtre elliptique
;Region2 = CreateEllipticRgn_(20, 20, WindowHeight(fenetre)-20, WindowHeight(fenetre)-20) ; Création de la région pour faire une fenêtre elliptique
;CombineRgn_(Region, Region, Region2, #RGN_DIFF) ; On combine les 2 régions
SetWindowRgn_ ( WindowID (fenetre), Region, #True ) ; On applique la région
DeleteObject_ (Region) ; On supprime la région
EndIf
EndProcedure
Procedure RemoveFromTaskbar(hwnd)
If IsWindow_ (hwnd)
a=hwnd : b= GetWindowLong_ (a, #GWL_HWNDPARENT ) : If b<>0 : a=b : EndIf ; Needed for "TaskAssign.exe".
ShowWindow_ (a, #SW_HIDE ) : GetWindowRect_ (a,win.RECT) : w=win\right-win\left : h=win\bottom-win\top
SetWindowLong_ (a, #GWL_EXSTYLE , #WS_EX_TOOLWINDOW ) : SetWindowPos_ (a,0,0,0,w-1,h-1, #SWP_NOMOVE )
SetWindowPos_ (a,0,0,0,w,h, #SWP_NOMOVE|#SWP_SHOWWINDOW ) : ProcedureReturn 1
EndIf
EndProcedure
Procedure WindowCallback( WindowID ,message,wParam,lParam)
res= #PB_ProcessPureBasicEvents
If message= #WM_PAINT ; on repaint la fenetre
dessin_horloge()
ElseIf message= #WM_MOVE ; au cas ou l'on bouge la fenetre
dessin_horloge()
ElseIf message = #dobro ; chaque seconde
;
StartDrawing ( WindowOutput ( #fenetre ))
Circle (xa, ya, 100 , RGB (0,0,0))
StopDrawing ()
For i=1 To sprite-1
sprite2(i)\Y=sprite2(i)\Y+sprite2(i)\vitesse
If sprite2(i)\Y>WindowHeight( #fenetre )
sprite2(i)\Y=0
EndIf
StartDrawing ( WindowOutput ( #fenetre ))
Circle (sprite2(i)\x,sprite2(i)\Y,1, RGB (sprite2(i)\ couleur_r,sprite2(i)\ couleur_v,sprite2(i)\ couleur_b))
StopDrawing ()
Next i
Else
ProcedureReturn #PB_ProcessPureBasicEvents ; rend la main !
EndIf
EndProcedure
;{ ****************** dessin de l'horloge **********************
Procedure dessin_horloge()
StartDrawing ( WindowOutput ( #fenetre ))
DrawingMode ( #PB_2DDrawing_Transparent )
DrawText (xa- TextWidth ( "By Dobro" )/2, rezy/2+50, "By Dobro" , RGB ($FD,$B,$8A), RGB ($0,$0,$0))
DrawText (ya- TextWidth ( Str (Heure)+ ":" + Str ( Minute )+ ":" + Str (Seconde))/2, rezy/2, Str (Heure)+ ":" + Str ( Minute )+ ":" + Str (Seconde) , RGB ($F7,$52,$28 ), RGB ($0,$0,$0))
StopDrawing ()
For a=1 To 60
degres =degres+6 : If degres=360:degres=0: EndIf : ; cela fait tourner
x= RotationX(xa, degres, distance)
Y= RotationY(ya, degres, distance)
quart=quart+1
If quart=15
quart=0
StartDrawing ( WindowOutput ( #fenetre ))
Circle (x,Y,8, RGB ($FF,$2D,$2D))
StopDrawing ()
EndIf
min=min+1
min_col=min_col+8
If min_col>255
min_col=10
Delay (25)
EndIf
If min<>15
StartDrawing ( WindowOutput ( #fenetre ))
Circle (x,Y,4, RGB (min_col,20,20))
StopDrawing ()
Else
min=0
EndIf
min2=min2+1
If min2=5
StartDrawing ( WindowOutput ( #fenetre ))
Circle (x,Y,4, RGB ($E7,$F0,$39))
StopDrawing ()
min2=0
EndIf
Next a
EndProcedure
;} ****************************************************************************


