'===========================================================================
' Subject: Get Tic Count                      Date: 06-07-01 (  :  )       
'  Author: Scott Slater                       Code: PBDLL ver 6.0          
'  Origin:                                  Packet: PBDLL.ABC
'===========================================================================
'SUBJECT: Getting Systems Uptime
'Author: Scott Slater
'Origin: sslater@summitcn.com
'Code: PB DLL v6
'Packet: Windows API
'============================================================================
'
' Here is a demonstration of using the GetTickCount API to
' get the system uptime.  The GetTickCount will return the
' number of miliseconds that the system has been running in
' a DWORD.  The Function GetSystemUpTime will return a string
' in a 00:00:00:00.000 format that includes days, hours,
' minutes, seconds, and miliseconds. (DD:HH:MM:SS.Msec)
'
' This code requires PBDLL v6 to compile since it uses DDT.
'
'                           Enjoy!
'                              Scott Slater
'
#Compile Exe
#Dim All

%SS_SUNKEN = &H1000&
%SS_CENTER = &H0001&

Declare Function GetTickCount Lib "KERNEL32.DLL" Alias "GetTickCount" ()_
              As Dword

Function GetSystemUpTime() As String

   Local tics   As Dword
   Local Days   As Long
   Local Hrs    As Long
   Local Mins   As Long
   Local Secs   As Long
   Local UpTime As String

   tics = GetTickCount        ' API Function

   Days = tics \ (1000 * 3600 * 24)         ' Get Days
   tics = tics - (Days * 1000 * 3600 * 24)  ' Subtract Days
                                            '   from tics
   Hrs = tics \ (1000 * 3600)               ' Get Hours
   tics = tics - (Hrs * 1000 * 3600)        ' Subtract Hours
                                            '   from tics
   Mins = tics \ (1000 * 60)                ' Get Minutes
   tics = tics - (Mins * 1000 * 60)         ' Subtract Mins
                                            '   from tics
   Secs = tics \ 1000                       ' Get Seconds
   tics = tics - (Secs * 1000)              ' Subtract Secs
                                            '   from tics
   ' Build Time String with all components
   UpTime = Format$(Days,"00") & ":" & Format$(Hrs,"00") & ":" & _
            Format$(Mins,"00") & ":" & Format$(Secs,"00") & "." & _
            Format$(Tics,"000")

   Function = UpTime

End Function

CallBack Function Refresh
   Control Set Text CbHndl, 100, GetSystemUpTime
End Function

CallBack Function QuitPrg
   Dialog End CbHndl, 0
End Function

Function PbMain As Long

   Local hDlg As Long

   Dialog New 0, "System UpTime Demo",,,100, 55 To hDlg
   Control Add Label, hDlg, -1, "System UpTime", 10, 5, 80, 8
   Control Add Label, hDlg, 100, "", 10, 16, 80, 10, %SS_SUNKEN Or %SS_CENTER
   Control Add Button, hDlg, 200, "&Quit", 10, 35, 35, 14 Call QuitPrg
   Control Add Button, hDlg, 210, "&Refresh", 55, 35, 35, 14 Call Refresh
   Control Set Text hDlg, 100, GetSystemUpTime
   Dialog Show Modal hDlg

End Function

               
