It is currently Sat Mar 06, 2021 6:15 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Timer Events
PostPosted: Sat Sep 06, 2003 4:25 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Mon Jun 02, 2003 1:42 am
Posts: 2010
Location: Ashland, KY
Code updated For 5.20+

Probably known well by others but I ran across this today searching the forum and thought I'd bring it up again

HighResTimer userlib has a timer in it but this is a little different

Code:
settimer_(WindowID,TimerID,Time_in_ms,0)


That will send a #WM_TIMER event every Time_in_ms

Code:
killtimer_(WindowID,TimerID)


That will stop the timer..

Pretty handy!

_________________
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 06, 2003 10:47 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 8:39 pm
Posts: 225
If I want to set multiple timers, how do I know which timer was triggered?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 06, 2003 3:01 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5821
Location: Germany
When receiving the #WM_TIMER message, the wParam value holds the
TimerID you specified when creating the timer.

Timo

_________________
quidquid Latine dictum sit altum videtur


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 06, 2003 3:13 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 904
Location: Cuernavaca, Mexico
I found this source code in my PB folders. It was written by Danilo, I searched the PureBasic Forum, but couldn't locate it, so I'm including it here. It shows 2 timers in use at one time.

Code:
;-------------------------------------------------
; Another great little demo from Danilo on timers
; and scrolling.
;-------------------------------------------------

Global myText$
Global hWnd.l
Global TextLength.l
#ScrollSpeed_in_Milliseconds = 70


myText$ = "     This is a little Scroller-Test with the Timer by Danilo     "
TextLength = Len(myText$)


Procedure Scroller()
;Shared Scroller_a
Shared Scroller_Position
Shared Scroller_Direction

If Scroller_Position < TextLength + 1 And Scroller_Direction = 0
    TEMP$ = Right(myText$,Scroller_Position)
    SetWindowText_(hWnd, TEMP$)
    Scroller_Position+1
Else
    Scroller_Direction = 1
    TEMP$ = Right(myText$,Scroller_Position)
    SetWindowText_(hWnd, TEMP$)
    Scroller_Position-1
    If Scroller_Position = 0 : Scroller_Direction = 0 : EndIf
EndIf
EndProcedure


Procedure mybeep()
  beep_(500,1000)
  EndTimer(0)
  DisableGadget(0,0)
  DisableGadget(1,0)
  StartTimer(1, #ScrollSpeed_in_Milliseconds, @Scroller())
EndProcedure


Procedure Alarm()
  beep_(500,60)
EndProcedure


MessageRequester("Minimal Timer Resolution",Str(GetMinTimerResolution()),0)
MessageRequester("Maximal Timer Resolution",Str(GetMaxTimerResolution()),0)


hWnd = OpenWindow(0, (GetSystemMetrics_(#SM_CXSCREEN)-400)/2,(GetSystemMetrics_(#SM_CYSCREEN)-100)/2, 400, 100, #PB_Window_SystemMenu,"")


  If CreateGadgetList(WindowID())
    ButtonGadget(0,  10, 10, 100, 25, "Quit Scroller")
    DisableGadget(0,1)
    ButtonGadget(1, 120, 10, 250, 25, "Change Timer from Scroller to Beep")
    DisableGadget(1,1)
  EndIf
SetForeGroundWindow_(hWnd)


StartTimer(0,1000, @mybeep())

;message loop
  Repeat
           EventID.l=WaitWindowEvent()
              If EventID = #PB_EventGadget
                 Select EventGadgetID()
                  Case 0 ; End the Timer
                    A$ = GetGadgetText(0)
                    If A$ = "Quit Alarm"
                       SetGadgetText(0,"Exit Program")
                       DisableGadget(1,1)
                    EndIf
                    If A$ = "Exit Program"
                       Quit = 1
                    EndIf
                    EndTimer(1)
                  Case 1
                    SetGadgetText(0,"Quit Alarm")
                    StartTimer(1, 100, @Alarm())
                 EndSelect
              EndIf
              ; pressed CloseButton or ALT+F4 ??
              If EventID = #PB_EventCloseWindow
                 Quit = 1
              EndIf
  Until Quit = 1
; the end


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 06, 2003 3:14 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 8:39 pm
Posts: 225
Thanks, guys!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 06, 2003 9:25 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Mon Jun 02, 2003 1:42 am
Posts: 2010
Location: Ashland, KY
Doh. Sorry for not explaining detecting the events. I came in from the bar a little late last night if you know what I mean :-)

_________________
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


Top
 Profile  
Reply with quote  
 Post subject: Re: Timer Events
PostPosted: Fri Mar 24, 2017 8:25 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8149
Location: Fort Nelson, BC, Canada
It's low res though. For API, TimeSetEvent_() will perform to the single millisecond and even the native ElapsedMilliseconds() will do likewise since its update a couple of years back. With SetTimer_() the best granularity you will achieve is the OS refresh rate, which is around 15ms.

_________________
BERISHEET


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: filip, mk-soft and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye