Accurate Timer

Category: Time/Timers

Date: 02-16-2022

Return to Index


 
'Compilable Example:  (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Global qFreq, qStart, qStop As Quad
 
Function PBMain() As Long
   Dialog New Pixels, 0, "Sleep Replacement",300,300,200,200, %WS_OverlappedWindow To hDlg
   Control Add Button, hDlg, 100,"Test", 20,10,120,20
   Dialog Show Modal hDlg Call DlgProc
End Function
 
CallBack Function DlgProc() As Long
   Select Case Cb.Msg
      Case %WM_InitDialog
         QueryPerformanceFrequency qFreq
      Case %WM_Command
         Select Case Cb.Ctl
            Case 100
               QueryPerformanceCounter qStart
               AccurateSleep 2.5
               QueryPerformanceCounter qStop
               ? Format$((qStop-qStart)/qFreq,"###.000") & " seconds"
         End Select
   End Select
End Function
 
Sub AccurateSleep(s As Single)
   Local qStartX, qStopX, qFreqX As Quad, Flag As Long
   QueryPerformanceFrequency qFreqX
   QueryPerformanceCounter qStartX
   Do
      QueryPerformanceCounter qStopX
      If (qStopX-qStartX)/qFreqX >= s Then Flag = 1
      Dialog DoEvents
   Loop Until Flag
End Sub
 
'gbs_00589
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm