Home aSocks Sample File: Time/TimeZoneGUI.prg
Sample Application Files
Encode:
  • Encode.prg
  • Finger:
  • Finger.prg
  • HTTP:
  • HTTPGrabContentGUI.prg
  • HTTPHeaderCRT.prg
  • HTTPHeaderGUI.prg
  • HTTPLinkListCRT.prg
  • HTTPRequestCRT.prg
  • SSL_POST.prg
  • RawWrite.prg
  • MIME:
  • MIME_Dlg.prg
  • NNTP:
  • NewsCheckCRT.prg
  • NewsCheckGUI.prg
  • SMTP:
  • CommandLineMailer.prg
  • SendMail.prg
  • SendMailGUI.prg
  • Telnet:
  • TelnetDemo.prg
  • TelnetGUI.prg
  • Time:
  • GrabTime.prg
  • TimeZoneCRT.prg
  • TimeZoneGUI.prg
  • WhoIs:
  • WhoIs.prg
  • //********************************************************
    //   Project: Time Zone Differential Display - GUI Version
    //********************************************************
    //    Author: Michael Mc Vicker
    // Copyright: © 01/19/01 - All Rights Reserved
    //  FileName: TimeZoneGUI.PRG
    //********************************************************
    //
    // aSocks Sample Application:
    //    Sample application to demonstrate the functionallity
    //    of the aSocks TCP/IP Library.
    //
    //  Components:
    //    aprTime Class
    //
    // Updates:
    //  Last Update: 01/19/01 by MMM
    //
    // Notes:
    //
    //********************************************************
    #pragma Library( "XppUI2.LIB" )
    #pragma Library( "ADAC20b.LIB" )
    
    #include "Gra.ch"
    #include "Xbp.ch"
    #include "Common.ch"
    #include "Appevent.ch"
    #include "Font.ch"
    
    #Include "CSKeys.ch"
    #Include "ASocksKey.ch"
    #define CR_LF  Chr(13)+Chr(10)
    
    //*******************************
    Procedure AppSys ( )
    // Supress CRT Window from Opening
    Return
    
    //*******************************
    Procedure DBESys ( )
    //** Stop Requiremnet of Database DLLs ***
    Return
    
    //*******************************
    PROCEDURE Main
    //*******************************
      LOCAL nEvent, oXbp, mp1, mp2, oDlg
      Local n1 := 0, n2 := -5, n3 := 1, n4 := -8
      Local oTime, nTime := 0, aTime[2]
    
      // Create TIME Object
      oTime := aprTime():New(ASOCKS_LICENSE_KEY,CSTOOLS_LICENSE_KEY)
      oTime:Debug := .F.
      // Create DIALOG
      oDlg := dlgTimeZone():New():Create()
      oDlg:MenuBar():addItem( { "~Quit",      {|| PostAppEvent( xbeP_Close ) } } )
      oDlg:MenuBar():addItem( { "~Check Time",{|| nTime := oTime:GetNetworkTime("ntp2.usno.navy.mil",,5), aTime := oTime:ConvertNetworkTime(nTime, .T.), aprMsg("Date: "+DtoC(aTime[1])+CR_LF+"Time: "+aTime[2],"Time Server Date/Time:") } } )
      oDlg:MenuBar():addItem( { "~Set Clock", {|| nTime := oTime:GetNetworkTime("ntp2.usno.navy.mil",,5), oTime:UpdateLocalTime( nTime ) } } )
      oDlg:MenuBar():addItem( { "~Debug",     {|| oTime:Debug := !oTime:Debug, aprMsg("Debug is "+iif(oTime:Debug,"ON", "OFF"),"oTime:Debug:") } } )
    
      // Show updated time every 1 Second
      SetTimerEvent( 100, {|| TimeDisplay( oDlg, oTime, n1, n2, n3, n4, 5 ) } )
      // Pre-Load nEvent
      nEvent := xbe_None
      WHILE nEvent != xbeP_Close
        nEvent := AppEvent ( @mp1, @mp2, @oXbp )
        oXbp:HandleEvent ( nEvent, mp1, mp2 )
        IF nEvent == xbeP_Close
          SetTimerEvent(0)
          oTime:Destroy()
          QUIT   // AppQuit()
        ENDIF
      ENDDO
    RETURN
    
    //*******************************
    Procedure TimeDisplay ( oDlg, oTime, n1, n2, n3, n4, nLen )
    //*******************************
      Local nTime := -1
      nTime := oTime:CreateLocalTime()
      oDlg:st1:SetCaption(Substr(AdjustTime(nTime, n1, oTime )[2],1,nLen+3)+CR_LF+DtoC(AdjustTime(nTime, n1, oTime )[1]))
      oDlg:st2:SetCaption(Substr(AdjustTime(nTime, n2, oTime )[2],1,nLen)+CR_LF+DtoC(AdjustTime(nTime, n2, oTime )[1]))
      oDlg:st3:SetCaption(Substr(AdjustTime(nTime, n3, oTime )[2],1,nLen)+CR_LF+DtoC(AdjustTime(nTime, n3, oTime )[1]))
      oDlg:st4:SetCaption(Substr(AdjustTime(nTime, n4, oTime )[2],1,nLen)+CR_LF+DtoC(AdjustTime(nTime, n4, oTime )[1]))
    Return
    
    //*******************************
    Function AdjustTime ( nTime, nAdjust, oTime )
    //*******************************
    Return oTime:ConvertNetworkTime(nTime+(nAdjust*3600))
    
    
    // ******************************************************************************
    // Construct Time Zone Dialog CLASS
    // ******************************************************************************
    CLASS dlgTimeZone FROM xbpDialog
       EXPORTED:
          VAR editControls
          VAR Static1
          VAR Static2
          VAR Static3
          VAR Static4
          VAR st1
          VAR st2
          VAR st3
          VAR st4
          VAR Static5
    
          METHOD init
          METHOD create
    ENDCLASS
    
    // ******************************************************************************
    // Initialize the Time Zone Dialog
    // ******************************************************************************
    METHOD dlgTimeZone:init( oParent, oOwner, aPos, aSize, aPP, lVisible )
       DEFAULT oParent  TO AppDesktop(), ;
               aPos     TO {526,415}, ;
               aSize    TO {274,186}, ;
               lVisible TO .F.
    
       DEFAULT aPP TO {}
       AAdd ( aPP, { XBP_PP_COMPOUNDNAME, "8.Arial" } )
       ::XbpDialog:init( oParent, oOwner, aPos, aSize, aPP, lVisible )
       ::XbpDialog:taskList   := .T.
       ::XbpDialog:MaxButton  := .F.
       ::XbpDialog:title      := "aSocks Time Zone Display"
       ::XbpDialog:keyBoard   := {| nKeyCode, uNIL, self | iif(nKeyCode = 27, PostAppEvent(xbeP_Close),) }
       ::XbpDialog:MinSize    := {274,186}
       ::XbpDialog:MaxSize    := {274,186}
    
       ::editControls := {}
    
       ::Static1   := XbpStatic():new( ::drawingArea, , {4,72}, {128,64} )
       ::Static1:caption := "GMT"
       ::Static1:clipSiblings := .T.
       ::Static1:type := XBPSTATIC_TYPE_GROUPBOX
    
       ::Static2   := XbpStatic():new( ::drawingArea, , {136,72}, {128,64} )
       ::Static2:caption := "Pittsburgh, PA, U.S."
       ::Static2:clipSiblings := .T.
       ::Static2:type := XBPSTATIC_TYPE_GROUPBOX
    
       ::Static3   := XbpStatic():new( ::drawingArea, , {4,4}, {128,64} )
       ::Static3:caption := "Germany"
       ::Static3:clipSiblings := .T.
       ::Static3:type := XBPSTATIC_TYPE_GROUPBOX
    
       ::Static4   := XbpStatic():new( ::drawingArea, , {136,4}, {128,64} )
       ::Static4:caption := "Pacific, U.S."
       ::Static4:clipSiblings := .T.
       ::Static4:type := XBPSTATIC_TYPE_GROUPBOX
    
       ::st1     := XbpStatic():new( ::drawingArea, , {12,76}, {116,48}, { { XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
       ::st1:caption := "GMT"
       ::st1:clipSiblings := .T.
       ::st1:options      := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_WORDBREAK
    
       ::st2 := XbpStatic():new( ::drawingArea, , {144,76}, {116,48}, { { XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
       ::st2:caption := "Pitsburgh, PA"
       ::st2:clipSiblings := .T.
       ::st2:options  := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_WORDBREAK
    
       ::st3 := XbpStatic():new( ::drawingArea, , {12,8}, {116,48}, { { XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
       ::st3:caption := "Germany"
       ::st3:clipSiblings := .T.
       ::st3:options  := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_WORDBREAK
    
       ::st4   := XbpStatic():new( ::drawingArea, , {144,8}, {116,48}, { { XBP_PP_COMPOUNDNAME, "16.Times New Roman" } } )
       ::st4:caption := "Pacific, U.S."
       ::st4:clipSiblings := .T.
       ::st4:options    := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_WORDBREAK
    
       ::Static5   := XbpStatic():new( ::drawingArea, , {0,139}, {268,1} )
       ::Static5:caption := ""
       ::Static5:clipSiblings := .T.
       ::Static5:type := XBPSTATIC_TYPE_RECESSEDLINE
    RETURN self
    
    
    // ******************************************************************************
    // Request system resources and Display Time Zone Dialog
    // ******************************************************************************
    METHOD dlgTimeZone:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
       // Create Time Zone Dialog
       ::XbpDialog:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
       ::Static1:create()
       ::Static2:create()
       ::Static3:create()
       ::Static4:create()
       ::st1:create()
       ::st2:create()
       ::st3:create()
       ::st4:create()
       ::Static5:create()
    
       // Display Dialog and Set System Focus
       SetAppFocus( Self )
       ::show()
    
    RETURN self