home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 24 / PCPLUS115.iso / dbasewin / samples / dbclock.prg < prev    next >
Encoding:
Text File  |  1994-08-02  |  11.6 KB  |  371 lines

  1. *******************************************************************************
  2. *  PROGRAM:      DBClock.prg
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         12/93
  7. *
  8. *  UPDATED:      4/93
  9. *
  10. *  REVISION:     $Revision:   1.29  $
  11. *
  12. *  VERSION:      dBASE FOR WINDOWS 5.0
  13. *
  14. *  DESCRIPTION:  This is a digital non-mdi clock that you can modify to your
  15. *                liking. It can run in the background while other
  16. *                dBASE for Windows programs are running.
  17. *                This program uses the DBTimer VBX control to update the clock.
  18. *                You can modify the way this clock looks by selecting
  19. *                desired options from the options menu.
  20. *                You can modify the font, color, and time display.
  21. *                The size of the time characters will change as you resize
  22. *                the clock form, but the time display should always be
  23. *                centered in the form.
  24. *
  25. *                WARNING:
  26. *                   If something goes awry, the timer might continue
  27. *                   running, and the dBASE for Windows Alert window will come up
  28. *                   with each clock tick.  This could cause problems.
  29. *
  30. *  PARAMETERS:   None
  31. *
  32. *  CALLS:        DBTimer.vbx
  33. *
  34. *  USAGE:        Do DBClock
  35. *
  36. *******************************************************************************
  37. create session
  38. set talk off
  39. set ldCheck off
  40. set design off
  41.  
  42. set procedure to program(1) additive
  43. local f
  44. f = new ClockForm()
  45. f.open()
  46.  
  47. *******************************************************************************
  48. *******************************************************************************
  49. class ClockForm of Form
  50. *******************************************************************************
  51.  
  52.    this.top = 0
  53.    this.left = 65.38
  54.    this.height = 4.08
  55.    this.width = 11.22
  56.    this.mdi = .f.
  57.    this.minimize = .t.
  58.    this.text = "Clock"
  59.    this.sizeable = .t.
  60.    this.moveable = .t.
  61.    this.sysMenu = .t.
  62.    this.colorNormal = "bg+/n"
  63.  
  64.    define text timeText of this;
  65.       property;
  66.          text time(),;
  67.          alignment 4,;
  68.          colornormal "bg+/n",;
  69.          height 6.12,;
  70.          width 11.22,;
  71.          fontName "Sans Serif",;
  72.          fontBold .f.
  73.  
  74.    load dll dbtimer.vbx
  75.    define dbtimer timer of this;
  76.       property;
  77.          Width          4.62,;
  78.          Height          2.37,;
  79.          Top          300.06,;
  80.          Left         300.12,;
  81.          OnTimer {;form.timeText.text = form.GetTime()}
  82.    this.TimeProperty = CLASS::TimeProperty
  83.    this.DefineMenu()
  84.  
  85.    *******************************************************************************
  86.    procedure OnOpen
  87.    *******************************************************************************
  88.    private optionsRef
  89.  
  90.    public formatMenuChecked,colorNormalMenuChecked,fontNameMenuChecked,;
  91.       fontBoldMenuChecked,fontItalicMenuChecked
  92.  
  93.    *** safety
  94.  
  95.  
  96.    ***
  97.  
  98.    this.menuReleased = .f.             && -- Indicates that form has no menu
  99.    this.timeFormat = 0                 && -- Format of the time text
  100.    this.GetTime = Get24Time            && -- Function called to display the time.
  101.                                        && GetTime will be set to Get24Time or
  102.                                        && Get12Time depending on the format
  103.                                        && menu option selected.
  104.  
  105.    optionsRef = this.MainMenu.Options  && So don't have to access reference
  106.                                        && each time
  107.  
  108.    formatMenuChecked      = optionsRef.Formats.TwentyFourHrFormat
  109.    colorNormalMenuChecked = optionsRef.Colors.CyanColor
  110.    fontNameMenuChecked    = optionsRef.Fonts.SansSerifFont
  111.    fontBoldMenuChecked    = optionsRef.Bold.BoldOff
  112.    fontItalicMenuChecked  = optionsRef.Italic.ItalicOff
  113.    this.OnSize(.f.,this.width,this.height)  && initial sizing
  114.    this.timer.enabled     = .t.
  115.  
  116.    *******************************************************************************
  117.    procedure OnClose
  118.  
  119.    * Release all public variables.  This will be unnecessary when they
  120.    * will be properties.
  121.    *******************************************************************************
  122.    set design on
  123.    release formatMenuChecked,colorNormalMenuChecked,fontNameMenuChecked,;
  124.       fontBoldMenuChecked,fontItalicMenuChecked
  125.    close procedure program(1)
  126.  
  127.    *******************************************************************************
  128.    procedure OnGotFocus
  129.    *******************************************************************************
  130.    set design off
  131.  
  132.    *******************************************************************************
  133.    procedure OnLostFocus
  134.    *******************************************************************************
  135.    set design on
  136.  
  137.    *******************************************************************************
  138.    procedure OnSize (nType, width, height)
  139.  
  140.    * Resize the text to the form
  141.    *******************************************************************************
  142.    local t
  143.  
  144.    t = form.timeText
  145.    t.width = width
  146.    t.height = height
  147.    t.fontSize = (height + width)/2
  148.  
  149.    *******************************************************************************
  150.    procedure TwelveHour
  151.  
  152.    * Set up the time display to use 12 hour representation
  153.    *******************************************************************************
  154.    if this.timeFormat <> 12
  155.       this.timeFormat = 12
  156.       this.GetTime = Get12Time
  157.    endif
  158.  
  159.    ********************************************************************************
  160.    procedure TwentyFourHour
  161.  
  162.    * Set up the time display to use 24 hour representation
  163.    ********************************************************************************
  164.    if this.timeFormat <> 24
  165.       this.timeFormat = 24
  166.       this.GetTime = Get24Time
  167.    endif
  168.  
  169.    ****************************************************************************
  170.    procedure TimeProperty
  171.  
  172.    * check the current menu item, and uncheck the previously checked item
  173.    * in that group.  Set the corresponding property of the text control.
  174.    ****************************************************************************
  175.    private propRef,propName,t,menuVar,proc
  176.    propName = this.parent.value
  177.    menuVar = propName + "MenuChecked"
  178.    &menuVar..checked = .f. && Uncheck group's checked menu
  179.    this.Checked = .t.
  180.    &menuVar = this    && This is now the checked menu.
  181.    if propName <> "Format"         && Change a property of the text control
  182.       t = form.timeText
  183.       propRef = "t." + propName
  184.       &propRef = this.value
  185.    else                            && Change the format of the text
  186.       proc = "form." + this.procName
  187.       &proc()
  188.    endif
  189.  
  190.  
  191.    *******************************************************************************
  192.    procedure DefineMenu
  193.  
  194.    * Create a menu for the clock
  195.  
  196.    *******************************************************************************
  197.  
  198.    define menu MainMenu of this
  199.  
  200.    define menu Options of this.MainMenu;
  201.       property;
  202.          text "&Options"
  203.  
  204.    define menu ExitMenu of this.MainMenu.Options;
  205.       property;
  206.          text "&Exit",;
  207.          onclick {;form.Close()}
  208.  
  209.    define menu Separator1 of this.MainMenu.Options;
  210.       property;
  211.          separator .t.
  212.  
  213.    define menu Colors of this.MainMenu.Options ;
  214.       property;
  215.          text "&Colors";
  216.       custom;
  217.          value "ColorNormal"
  218.    define menu CyanColor of this.MainMenu.Options.Colors;
  219.       property;
  220.          text "&Cyan",;
  221.          onclick this.TimeProperty,;
  222.          checked .t.;
  223.       custom;
  224.          value "bg+/n"
  225.    define menu YellowColor of this.MainMenu.Options.Colors;
  226.       property;
  227.          text "&Yellow",;
  228.          OnClick this.timeProperty;
  229.       custom;
  230.          value "gr+/n"
  231.    define menu MagentaColor of this.MainMenu.Options.Colors;
  232.       property;
  233.          text "&Magenta",;
  234.          OnClick this.timeProperty;
  235.       custom;
  236.          value "rb+/n"
  237.    define menu RedColor of this.MainMenu.Options.Colors;
  238.       property;
  239.          text "&Red",;
  240.          onclick this.timeProperty;
  241.       custom;
  242.          value "r+/n"
  243.  
  244.    define menu Separator2 of this.MainMenu.Options;
  245.       property;
  246.          separator .t.
  247.    define menu Formats of this.MainMenu.Options;
  248.       property;
  249.          text "&Formats";
  250.       custom;
  251.          value "Format"
  252.    define menu TwentyFourHrFormat of this.MainMenu.Options.Formats;
  253.       property;
  254.          text "Twenty Four Hour",;
  255.          onclick this.TimeProperty,;
  256.          checked .t.;
  257.       custom;
  258.          procName "TwentyFourHour"
  259.    define menu TwelveHrFormat of this.MainMenu.Options.Formats;
  260.       property;
  261.          text "Twelve Hour",;
  262.          onclick this.TimeProperty;
  263.       custom;
  264.          procName "TwelveHour"
  265.  
  266.    define menu Separator3 of this.MainMenu.Options;
  267.       property;
  268.          separator .t.
  269.    define menu Fonts of this.MainMenu.Options;
  270.       property;
  271.          text "&Fonts";
  272.       custom;
  273.          value "FontName"
  274.    define menu ArialFont of this.MainMenu.Options.Fonts;
  275.       property;
  276.          text "&Arial",;
  277.          onclick this.timeProperty;
  278.       custom;
  279.          value "Arial"
  280.    define menu ScriptFont of this.MainMenu.Options.Fonts;
  281.       property;
  282.          text "&Script",;
  283.          onclick this.timeProperty;
  284.       custom;
  285.          value "Script"
  286.    define menu RomanFont of this.MainMenu.Options.Fonts;
  287.       property;
  288.          text "&Roman",;
  289.          onclick this.timeProperty;
  290.       custom;
  291.          value "Roman"
  292.    define menu SerifFont of this.MainMenu.Options.Fonts;
  293.       property;
  294.          text "S&erif",;
  295.          onclick this.timeProperty;
  296.       custom;
  297.          value "Serif"
  298.    define menu SansSerifFont of this.MainMenu.Options.Fonts;
  299.       property;
  300.          text "Sa&ns Serif",;
  301.          onclick this.timeProperty,;
  302.          checked .t.;
  303.       custom;
  304.          value "Sans Serif"
  305.    define menu Bold of this.MainMenu.Options;
  306.       property;
  307.          text "&Bold Fonts";
  308.       custom;
  309.          value "FontBold"
  310.    define menu BoldOff of this.MainMenu.Options.Bold;
  311.       property;
  312.          text "O&ff",;
  313.          onclick this.timeProperty,;
  314.          checked .t.;
  315.       custom;
  316.          value .F.
  317.    define menu BoldOn of this.MainMenu.Options.Bold;
  318.       property;
  319.          text "&On",;
  320.          onclick this.timeProperty;
  321.       custom;
  322.          value .t.
  323.    define menu Italic of this.MainMenu.Options;
  324.       property;
  325.          text "&Italic Fonts";
  326.       custom;
  327.          value "FontItalic"
  328.    define menu ItalicOff of this.MainMenu.Options.Italic;
  329.       property;
  330.          text "O&ff",;
  331.          onclick this.timeProperty,;
  332.          checked .t.;
  333.       custom;
  334.          value .f.
  335.    define menu ItalicOn of this.MainMenu.Options.Italic;
  336.       property;
  337.          text "&On",;
  338.          onclick this.timeProperty;
  339.       custom;
  340.          value .t.
  341.  
  342.  
  343. endclass
  344.  
  345. *******************************************************************************
  346. function Get12Time
  347.  
  348. * Create the string representing 12 hour time representation
  349.  
  350. *******************************************************************************
  351. local time,hours
  352.  
  353. time = time()
  354. hours = val(time)
  355. return ltrim(str(mod(hours-1,12)+1)) + ;
  356.          substr(time,3) + ;
  357.          iif(hours < 12," AM"," PM")
  358.  
  359.  
  360. *******************************************************************************
  361. function Get24Time
  362.  
  363. * Create the string representing 24 hour time representation
  364. *******************************************************************************
  365. return time()       && Time in dBASE for Windows is in 24 hour format
  366.  
  367.  
  368.  
  369.  
  370.  
  371.