afficher les seconde a l'ouverture

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
venom
Messages : 3138
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

afficher les seconde a l'ouverture

Message par venom »

bonjour.

voici ma question je n'arrive pas a faire pour qu'a l'ouverture de ma fenetre s'afiche les seconde en temps reel tout le temps que ma fenetre reste ouvert.

si vous avez pas comprit merci de me le faire part :D

voici un exemple

Code : Tout sélectionner

;- Window Constants
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
Enumeration
  #Text_0
  #Text_1
  #Text_2
EndEnumeration

;liste chainee

;- Fonts
Global FontID1
FontID1 = LoadFont(1, "Georgia", 10)
Global FontID2
FontID2 = LoadFont(2, "Comic Sans MS", 10, #PB_Font_Bold)
Global FontID3
FontID3 = LoadFont(3, "Comic Sans MS", 10, #PB_Font_Bold | #PB_Font_Italic)

  If OpenWindow(#Window_0, 216, 0, 240, 120,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "exemple")
    If CreateGadgetList(WindowID())

      TextGadget(#Text_1, 5, 50, 230, 20, "temps de connexion :  "+time$)
      SetGadgetFont(#Text_1, FontID3)

    EndIf
  EndIf
  
  Repeat 
  event = WaitWindowEvent() 
  If event = #PB_EventGadget 
    Select EventGadgetID() 

    EndSelect 
  EndIf  
Until event = #PB_EventCloseWindow
desoler c'est court j'ai pas trop le temps la


@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

comme çà ? :D

Code : Tout sélectionner

FontID0 = LoadFont(0, "Comic Sans MS", 10, #PB_Font_Bold | #PB_Font_Italic)

If OpenWindow(0, 216, 0, 240, 120,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "exemple")
  If CreateGadgetList(WindowID(0))
    TextGadget(0, 5, 50, 230, 20,"")
    SetGadgetFont(0,FontID0)
  EndIf
EndIf

SetTimer_(WindowID(0),1,100,#Null)

StartTime.l = ElapsedMilliseconds()

Repeat
  Select WaitWindowEvent()
    Case #PB_EventCloseWindow
      Break
    Case #PB_EventGadget
      Select EventGadgetID()
      EndSelect
    Case #WM_TIMER
      If EventwParam() = 1
        t.f=(ElapsedMilliseconds()-StartTime)/1000.0
        SetGadgetText(0,"temps de connexion : "+StrF(t,1)+" sec.")
      EndIf
  EndSelect
ForEver

KillTimer_(WindowID(0),1)
Image
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Ou comme çà ? :D

Code : Tout sélectionner

FontID0 = LoadFont(0, "Comic Sans MS", 10, #PB_Font_Bold | #PB_Font_Italic)

If OpenWindow(0, 216, 0, 240, 120,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "exemple")
  If CreateGadgetList(WindowID(0))
    TextGadget(0, 5, 50, 230, 20,"")
    SetGadgetFont(0,FontID0)
  EndIf
EndIf

StartTimer = ElapsedMilliseconds()

Repeat
  Select WindowEvent()
    Case #PB_EventCloseWindow
      Break
    Case #PB_EventGadget
      Select EventGadgetID()
      EndSelect
  EndSelect
  If ( ElapsedMilliseconds() - Timer ) > 100
    Timer = ElapsedMilliseconds()
    now.f = (Timer - StartTimer)/1000.0
    SetGadgetText(0,"temps de connexion : "+StrF(now,1)+" sec.")
  Else
    Delay(1)
  EndIf
ForEver
Image
Avatar de l’utilisateur
venom
Messages : 3138
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Message par venom »

exelent. :D

cool merci flype de ta reponse bonne et rapide


@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Allez encore une autre ? :D

Code : Tout sélectionner

Procedure myTimer(gadget.l)
  StartTimer.l = ElapsedMilliseconds()
  Repeat
    SetGadgetText(gadget,"temps de connexion : "+StrF(((ElapsedMilliseconds()-StartTimer)/1000.0),1)+" sec.")
    Delay(100)
  ForEver
EndProcedure

FontID0 = LoadFont(0, "Comic Sans MS", 10, #PB_Font_Bold | #PB_Font_Italic)

If OpenWindow(0, 216, 0, 240, 120, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "exemple")
  If CreateGadgetList(WindowID(0))
    TextGadget(0, 5, 50, 230, 20, "")
    SetGadgetFont(0,FontID0)
  EndIf
EndIf

CreateThread(@myTimer(),0)

Repeat
  Select WaitWindowEvent()
    Case #PB_EventCloseWindow: Break
  EndSelect
ForEver
Image
Avatar de l’utilisateur
Droopy
Messages : 1151
Inscription : lun. 19/juil./2004 22:31

Message par Droopy »

On peut aussi gérer le Timer en tant que Procédure/Timer

Code : Tout sélectionner

#Window_0=0 
#Text=0 

Procedure TpsCnxion()
  Static Debut
  If Debut=0 : Debut= Date() : EndIf
  SetGadgetText(#Text,FormatDate("%hhh %ii'' %ss'",Date()-Debut))
EndProcedure

OpenWindow(#Window_0, 0, 0, 240, 40,  #PB_Window_SystemMenu |#PB_Window_ScreenCentered , "Connexion depuis :") 
CreateGadgetList(WindowID()) 
TextGadget(#Text, 10, 10, 220, 20, "",#PB_Text_Center) 
settimer_(WindowID(),0,100,@TpsCnxion())

Repeat 
  event = WaitWindowEvent() 
Until event = #PB_EventCloseWindow
Répondre