home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch06 / time.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-15  |  6.2 KB  |  192 lines

  1. VERSION 4.00
  2. Begin VB.Form frmTime 
  3.    Caption         =   "Time Demonstration"
  4.    ClientHeight    =   3525
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1515
  7.    ClientWidth     =   4530
  8.    Height          =   3930
  9.    Left            =   1080
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3525
  12.    ScaleWidth      =   4530
  13.    Top             =   1170
  14.    Width           =   4650
  15.    Begin VB.Frame Frame1 
  16.       Caption         =   "Time Zone Info"
  17.       Height          =   2055
  18.       Left            =   60
  19.       TabIndex        =   6
  20.       Top             =   1140
  21.       Width           =   4095
  22.       Begin VB.TextBox txtTZSName 
  23.          Height          =   285
  24.          Left            =   1260
  25.          TabIndex        =   12
  26.          Top             =   960
  27.          Width           =   2115
  28.       End
  29.       Begin VB.TextBox txtTZBias 
  30.          Height          =   285
  31.          Left            =   1260
  32.          TabIndex        =   8
  33.          Top             =   360
  34.          Width           =   1515
  35.       End
  36.       Begin VB.TextBox txtTZName 
  37.          Height          =   285
  38.          Left            =   1260
  39.          TabIndex        =   7
  40.          Top             =   660
  41.          Width           =   2115
  42.       End
  43.       Begin VB.Label Label5 
  44.          Caption         =   "Savings Name:"
  45.          Height          =   195
  46.          Left            =   120
  47.          TabIndex        =   11
  48.          Top             =   1020
  49.          Width           =   1575
  50.       End
  51.       Begin VB.Label Label6 
  52.          Caption         =   "Time Diff."
  53.          Height          =   195
  54.          Left            =   120
  55.          TabIndex        =   10
  56.          Top             =   420
  57.          Width           =   675
  58.       End
  59.       Begin VB.Label Label7 
  60.          Caption         =   "Zone Name:"
  61.          Height          =   195
  62.          Left            =   120
  63.          TabIndex        =   9
  64.          Top             =   720
  65.          Width           =   975
  66.       End
  67.    End
  68.    Begin VB.TextBox txtAdjust 
  69.       Height          =   285
  70.       Left            =   1260
  71.       TabIndex        =   5
  72.       Top             =   660
  73.       Width           =   1515
  74.    End
  75.    Begin VB.TextBox txtSysTime 
  76.       Height          =   285
  77.       Left            =   1260
  78.       TabIndex        =   3
  79.       Top             =   360
  80.       Width           =   1515
  81.    End
  82.    Begin VB.TextBox txtLocTime 
  83.       Height          =   285
  84.       Left            =   1260
  85.       TabIndex        =   1
  86.       Top             =   60
  87.       Width           =   1515
  88.    End
  89.    Begin VB.Timer Timer1 
  90.       Interval        =   1000
  91.       Left            =   3540
  92.       Top             =   480
  93.    End
  94.    Begin VB.Label Label3 
  95.       Caption         =   "Adjustment:"
  96.       Height          =   195
  97.       Left            =   60
  98.       TabIndex        =   4
  99.       Top             =   720
  100.       Width           =   975
  101.    End
  102.    Begin VB.Label Label2 
  103.       Caption         =   "System Time:"
  104.       Height          =   195
  105.       Left            =   60
  106.       TabIndex        =   2
  107.       Top             =   420
  108.       Width           =   975
  109.    End
  110.    Begin VB.Label Label1 
  111.       Caption         =   "Local Time:"
  112.       Height          =   195
  113.       Left            =   60
  114.       TabIndex        =   0
  115.       Top             =   120
  116.       Width           =   1095
  117.    End
  118. Attribute VB_Name = "frmTime"
  119. Attribute VB_Creatable = False
  120. Attribute VB_Exposed = False
  121. Option Explicit
  122. Private Const LOCALE_SYSTEM_DEFAULT& = &H800
  123. Private Const LOCALE_USER_DEFAULT& = &H400
  124. '**********************************
  125. '**  Type Definitions:
  126. #If Win32 Then
  127. Private Type SYSTEMTIME
  128.         wYear As Integer
  129.         wMonth As Integer
  130.         wDayOfWeek As Integer
  131.         wDay As Integer
  132.         wHour As Integer
  133.         wMinute As Integer
  134.         wSecond As Integer
  135.         wMilliseconds As Integer
  136. End Type
  137. Private Type TIME_ZONE_INFORMATION
  138.         Bias As Long
  139.         StandardName As String * 64
  140.         StandardDate As SYSTEMTIME
  141.         StandardBias As Long
  142.         DaylightName As String * 64
  143.         DaylightDate As SYSTEMTIME
  144.         DaylightBias As Long
  145. End Type
  146. #End If 'WIN32 Types
  147. '**********************************
  148. '**  Function Declarations:
  149. #If Win32 Then
  150. Private Declare Function GetLocaleInfo& Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long)
  151. Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
  152. Private Declare Sub GetSystemTimeAdjustment Lib "kernel32" (lpTimeAdjustment As Long, lpTimeIncrement As Long, lpTimeAdjustmentDisabled As Long)
  153. Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
  154. Private Declare Function GetTimeZoneInformation& Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION)
  155. Private Declare Function GetTimeFormat& Lib "kernel32" Alias "GetTimeFormatA" _
  156.         (ByVal Locale As Long, ByVal dwFlags As Long, lpTime As SYSTEMTIME, _
  157.         ByVal lpFormat As Long, ByVal lpTimeStr As String, ByVal cchTime As Long)
  158. #End If 'WIN32
  159. Private Sub Form_Load()
  160.     Dim myTZ As TIME_ZONE_INFORMATION
  161.     Dim myAdj&, myIncr&, myDisabled&
  162.     Dim s$, dl&
  163.     GetSystemTimeAdjustment myAdj&, myIncr&, myDisabled&
  164.     If myDisabled& Then
  165.         txtAdjust = "Disabled."
  166.     Else
  167.         txtAdjust = myAdj& & " ns Every " & myIncr& & " ns."
  168.     End If
  169.     dl& = GetTimeZoneInformation(myTZ)
  170.     txtTZBias = CInt(myTZ.Bias / 30) / 2 & " hours"
  171.     s$ = myTZ.StandardName
  172.     txtTZName = StrConv(s$, vbFromUnicode)
  173.     s$ = myTZ.DaylightName
  174.     txtTZSName = StrConv(s$, vbFromUnicode)
  175. End Sub
  176. ' Obtain the system and local time and display them
  177. Private Sub Timer1_Timer()
  178.     Dim myTime As SYSTEMTIME, s$, dl&
  179.     GetLocalTime myTime
  180.     s$ = String$(255, Chr$(0))
  181.     dl& = GetTimeFormat&(LOCALE_SYSTEM_DEFAULT, 0, myTime, 0, s$, 254)
  182.     txtLocTime = s$
  183.     GetSystemTime myTime
  184.     s$ = String$(255, Chr$(0))
  185.     dl& = GetTimeFormat&(LOCALE_SYSTEM_DEFAULT, 0, myTime, 0, s$, 254)
  186.     txtSysTime = s$
  187. End Sub
  188. Private Sub txtNum_Change()
  189. End Sub
  190. Private Sub txtLocTime_Change()
  191. End Sub
  192.