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 / samples5 / ch06 / time.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-20  |  6.2 KB  |  189 lines

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