Timer procedure => transformation en Lib ?

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Timer procedure => transformation en Lib ?

Message par Ar-S »

Salut,

Du retour du pays des caribous j'aimerai faire une Lib "Clignote" qui permettrait de faire bêtement clignoter un texte.
Inspiré par le tuto de Dobro sur les timer et aidé de NetMaestro, voilà le code en question. (s'il peut servir à certain)

je n'arrive cependant pas à le modifier pour en faire une seule procédure que je compilerai en Lib.

Genre : Clignote(#GadgetCible,MessageAclignoter$,duree) ou même Clignote(#Fenetre,#GadgetCible,MessageAclignoter$,duree)

Merci de vos lumières.

Code : Tout sélectionner

; Timer pour clignoter par Ar-S
; thks to dobro & NetMestro
; PB . 4.30

Enumeration
  #WIN : #Affiche : #BT
EndEnumeration

Declare   TimerProc(hwnd.l, uMsg.l, idEvent.l, dwTime.l)
Declare Clignote(GadgetCible,MessageAclignoter$,duree)

Global GadgetCible=#Affiche
Global MessageAclignoter$="Clignoti clignota"

Procedure   TimerProc(hwnd.l, uMsg.l, idEvent.l, dwTime.l)
  ; thanks NetMaestro
  Static mode=0
  Select mode
    Case 0
      SetGadgetText(GadgetCible,MessageAclignoter$)
    Case 1
      SetGadgetText(GadgetCible,"")
  EndSelect
  mode = 1-mode
EndProcedure

Procedure Clignote(GadgetCible,MessageAclignoter$,duree)
    ;-TIMER---
SetTimer_(#WIN,0,duree, @TimerProc())
    ;---------
EndProcedure

Procedure OpenWindow_WIN()
  If OpenWindow(#WIN, 450, 200, 377, 24, "clignote", #PB_Window_SystemMenu|#PB_Window_TitleBar)
    
    StringGadget(#Affiche, 0, 0, 200, 22, "", #PB_String_ReadOnly|#ES_CENTER)
    ButtonGadget(#BT,210,0,150,20,"Clic")
  EndIf
EndProcedure


OpenWindow_WIN()


;{- Event loop
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Affiche
          ;Clignote(#Affiche,MessageAclignoter$,500)
        Case #BT
          Clignote(#Affiche,MessageAclignoter$,500)
      EndSelect
      
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #WIN
          CloseWindow(#WIN)
          Break
      EndSelect
  EndSelect
ForEver
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Timer procedure => transformation en Lib ?

Message par flaith »

ProcedureDLL ?
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Timer procedure => transformation en Lib ?

Message par Ar-S »

flaith a écrit :ProcedureDLL ?
:| ba ça n'a pas marché ! tu penses bien que j'ai essayé
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Timer procedure => transformation en Lib ?

Message par Backup »

ton code a une petite erreur , alors je sais pas si ça va resoudre ton probleme , mais pour info c'est

SetTimer_(WindowID(#win) ,0,duree, @TimerProc())

il faut utiliser le handle de la fenetre ! pas son numero

et bien sur ne pas oublier a la fin de ton prg de liberer le timer avec un

KillTimer_(WindowID(#win), 1) ;)
Avatar de l’utilisateur
MLD
Messages : 1124
Inscription : jeu. 05/févr./2009 17:58
Localisation : Bretagne

Re: Timer procedure => transformation en Lib ?

Message par MLD »

Bonjour Ar-S

Regarde ce sera peut-être utile

Code : Tout sélectionner

; Timer pour clignoter par Ar-S
; thks to dobro & NetMestro and MLD
; PB . 4.30

Enumeration
  #WIN 
  #BT
  #string_1
EndEnumeration
Declare clignote(idEvent,Affiche$) 
Global Affiche$

Procedure TimerProc(hwnd.l, uMsg.l, idEvent, dwTime.l) ;timer 
 Select uMsg 
  Case #WM_TIMER 
   Select idEvent 
    Case idEvent
     clignote(idEvent,Affiche$)
   EndSelect 
 EndSelect 
EndProcedure

Procedure clignote(idEvent,Affiche$)
  If GetGadgetText(idEvent) = ""
   SetGadgetText(idEvent,Affiche$)
  Else
    SetGadgetText(idEvent,"")
  EndIf  
EndProcedure


  If OpenWindow(#WIN, 450, 200, 377, 24, "clignote", #PB_Window_SystemMenu|#PB_Window_TitleBar)
    Handle = WindowID (#WIN ) ;Handle de la fenêtre
    StringGadget(#string_1, 0, 0, 200, 22, "", #PB_String_ReadOnly|#ES_CENTER)
    ButtonGadget(#BT,210,0,150,20,"Clic")
  EndIf


Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #BT
           Affiche$ ="Clignoti clignota"
           SetTimer_ (Handle, #string_1, 800, @TimerProc()) ;  Timer 
      EndSelect
      
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #WIN
          KillTimer_(WindowID(#win), 1)
          CloseWindow(#WIN)
          Break
      EndSelect
  EndSelect
ForEver

Bonne soirée.
Michel
Avatar de l’utilisateur
MLD
Messages : 1124
Inscription : jeu. 05/févr./2009 17:58
Localisation : Bretagne

Re: Timer procedure => transformation en Lib ?

Message par MLD »

Avec une seule procedure

Code : Tout sélectionner

; Timer pour clignoter par Ar-S
; thks to dobro & NetMestro and MLD
; PB . 4.30

Enumeration
  #WIN 
  #BT
  #string_1 = 2
  #string_2 = 3
EndEnumeration
Global Affiche$ 
Procedure TimerProc(hwnd.l, uMsg.l, idEvent$, dwTime.l) ;timer 
 idEvent = Val(Left(idEvent$,1))
 texte$ = Right( idEvent$,Len(idEvent$)-1)
 Select uMsg 
  Case #WM_TIMER 
   Select idEvent 
    Case 2
     If GetGadgetText(idEvent) = ""  
     SetGadgetText(idEvent,texte$)
    Else
    SetGadgetText(idEvent,"")
   EndIf
   EndSelect 
 EndSelect 
EndProcedure

  If OpenWindow(#WIN, 450, 200, 377, 60, "clignote", #PB_Window_SystemMenu|#PB_Window_TitleBar)
    Handle = WindowID (#WIN ) ;Handle de la fenêtre
    StringGadget(#string_1, 0, 0, 200, 22, "", #PB_String_ReadOnly|#ES_CENTER)
    StringGadget(#string_2, 0, 30, 200, 22, "Fixe", #PB_String_ReadOnly|#ES_CENTER)
    ButtonGadget(#BT,210,0,150,20,"Clic")
  EndIf


Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #BT
           Affiche$ = "2" + "Clignoti clignota"
           SetTimer_ (Handle, Affiche$, 800, @TimerProc()) ;  Timer 
      EndSelect
      
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #WIN
          KillTimer_(WindowID(#win), 1)
          CloseWindow(#WIN)
          Break
      EndSelect
  EndSelect
ForEver
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Timer procedure => transformation en Lib ?

Message par Ar-S »

Merci MLD,
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Répondre