home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / datetime / datetim1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-09-06  |  11.2 KB  |  296 lines

  1. VERSION 2.00
  2. Begin Form FullWindow 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "DateTime"
  6.    ClientHeight    =   210
  7.    ClientLeft      =   360
  8.    ClientTop       =   630
  9.    ClientWidth     =   2880
  10.    ForeColor       =   &H00FFFFFF&
  11.    Height          =   900
  12.    Icon            =   DATETIM1.FRX:0000
  13.    Left            =   300
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    ScaleHeight     =   210
  18.    ScaleWidth      =   2880
  19.    Top             =   0
  20.    Width           =   3000
  21.    Begin Timer Zeitmesser 
  22.       Index           =   1
  23.       Interval        =   1000
  24.       Left            =   0
  25.       Top             =   0
  26.    End
  27.    Begin Menu Menu 
  28.       Caption         =   "&Menu"
  29.       Begin Menu MenuClick 
  30.          Caption         =   "&Click"
  31.       End
  32.       Begin Menu Separator1 
  33.          Caption         =   "-"
  34.       End
  35.       Begin Menu MenuFormat 
  36.          Caption         =   "dddd ddddd ttttt"
  37.          Checked         =   -1  'True
  38.          Index           =   1
  39.       End
  40.       Begin Menu MenuFormat 
  41.          Caption         =   "dddd ddddd hh:mm"
  42.          Index           =   2
  43.       End
  44.       Begin Menu MenuFormat 
  45.          Caption         =   "ddd ddddd hh:mm"
  46.          Index           =   3
  47.       End
  48.       Begin Menu MenuFormat 
  49.          Caption         =   "dddd d-mmmm-yy h:mm:ss"
  50.          Index           =   4
  51.       End
  52.       Begin Menu MenuFormat 
  53.          Caption         =   "ddd dd-mmm-yy hh:mm"
  54.          Index           =   5
  55.       End
  56.       Begin Menu MenuFormat 
  57.          Caption         =   "ddd d/m/yy h:mm"
  58.          Index           =   6
  59.       End
  60.       Begin Menu MenuFormat 
  61.          Caption         =   "Enter your own format"
  62.          Index           =   7
  63.       End
  64.       Begin Menu Separator2 
  65.          Caption         =   "-"
  66.       End
  67.       Begin Menu MenuAbout 
  68.          Caption         =   "&About..."
  69.       End
  70.    End
  71.    Begin Menu MenuHelp 
  72.       Caption         =   "&Help"
  73.    End
  74. ' Program related declarations
  75. Const INIFILENAME$ = "DATETIME.INI"
  76. Dim HelpFilePath$, DTFormat$
  77. Sub Clear_MenuFormat_Checkmarks ()
  78.     For i% = 1 To 7
  79.         MenuFormat(i%).Checked = False
  80.     Next i%
  81. End Sub
  82. Sub Form_Load ()
  83.     Initialize
  84.     ' Get parameters from file (INIFILENAME$):
  85.     Left = GetPrivateProfileInt("DateTime", "Left", 300, INIFILENAME$)
  86.     Top = GetPrivateProfileInt("DateTime", "Top", 0, INIFILENAME$)
  87.     x$ = Space$(256)
  88.     i% = GetPrivateProfileString("DateTime", "Click", "no", x$, 255, INIFILENAME$)
  89.     x$ = Left$(x$, i%) ' Remove trailing Chr$(0) and other stuff
  90.     x$ = LTrim$(RTrim$(x$)) ' Remove leading and trailing blanks
  91.     x$ = UCase$(x$)
  92.     MenuClick.Checked = x$ = "YES" Or x$ = "TRUE" Or x$ = "ON" Or x$ = "1"
  93.     x$ = Space$(256)
  94.     i% = GetPrivateProfileString("DateTime", "FormatString", "Enter your own format", x$, 255, INIFILENAME$)
  95.     x$ = Left$(x$, i%) ' Remove trailing Chr$(0) and other stuff
  96.     x$ = LTrim$(RTrim$(x$)) ' Remove leading and trailing blanks
  97.     MenuFormat(7).Caption = x$
  98.     i% = GetPrivateProfileInt("DateTime", "FormatNumber", 1, INIFILENAME$)
  99.     Clear_MenuFormat_Checkmarks
  100.     ' Determine DTFormat$ and put check mark next to active format:
  101.     DTFormat$ = MenuFormat(i%).Caption
  102.     MenuFormat(i%).Checked = True
  103.     ' Determine own path to find help file later.
  104.     ' First get own path and file name:
  105.     HelpFilePath$ = Space$(128)
  106.     hModule% = GetClassWord(hWnd, GCW_HMODULE)
  107.     i% = GetModuleFileName(hModule%, HelpFilePath$, 127)
  108.     HelpFilePath$ = Left$(HelpFilePath$, i%) ' Remove chr$(0) and other stuff
  109.     ' Remove extension and replace with .WRI:
  110.     Do While Right$(HelpFilePath$, 1) <> "." And Len(HelpFilePath$)
  111.         HelpFilePath$ = Left$(HelpFilePath$, Len(HelpFilePath$) - 1)
  112.     Loop
  113.     HelpFilePath$ = HelpFilePath$ + "WRI"
  114.     ' Initialize display string:
  115.     DatTim$ = "Initializing, one moment please..."
  116.     Load SmallWindow
  117.     ' Load start timer which runs for one second only, then forces
  118.     ' WindowState from MINIMIZED to NORMAL to facilitate loading
  119.     ' from the WIN.INI load= line:
  120.     Load Zeitmesser(2)
  121.     Zeitmesser(2).Interval = 1000
  122. End Sub
  123. Sub Form_Paint ()
  124.     ' DatTim$ is a global variable containing the text to be displayed:
  125.     Cls: Print DatTim$;
  126.     If CurrentX Then
  127.         If CurrentX > 2000 Then
  128.             Width = CurrentX + 32
  129.         Else
  130.             Width = 2000
  131.         End If
  132.         SmallWindow.Width = CurrentX
  133.     End If
  134.     ' SmallWindow shall always follow FullWindow but is hidden
  135.     ' as long FullWindow is active:
  136.     SmallWindow.Left = Left
  137.     SmallWindow.Top = Top
  138. End Sub
  139. Sub Form_Resize ()
  140.     If WindowState <> MINIMIZED Then
  141.         ' Zeitmesser(1) timer when resized from icon to normal:
  142.         If Zeitmesser(1).Interval = 0 Then Zeitmesser(1).Interval = 1000
  143.     Else ' WindowState = MINIMIZED, i.e. an icon
  144.         ' If resized to icon then stop timer to reduce system load,
  145.         ' hide the small form and clear text so it does not display
  146.         ' over the icon:
  147.         Zeitmesser(1).Interval = 0
  148.         SmallWindow.Hide
  149.         SmallWindow.Cls
  150.         Cls
  151.     End If ' WindowState
  152.     ' Let the small form always follow the primary one:
  153.     SmallWindow.WindowState = WindowState
  154. End Sub
  155. Sub Form_Unload (Abbrechen%)
  156.     ' To make sure the parameters of the NORMAL window are saved,
  157.     ' not the ones of the icon in case the form is minimized:
  158.     WindowState = NORMAL
  159.     ' Write all parameters into DATETIME.INI:
  160.     i% = WritePrivateProfileString("DateTime", "Left", Str$(Left), INIFILENAME$)
  161.     i% = WritePrivateProfileString("DateTime", "Top", Str$(Top), INIFILENAME$)
  162.     If MenuClick.Checked Then x$ = "yes" Else x$ = "no"
  163.     i% = WritePrivateProfileString("DateTime", "Click", x$, INIFILENAME$)
  164.     x$ = MenuFormat(7).Caption
  165.     i% = WritePrivateProfileString("DateTime", "FormatString", x$, INIFILENAME$)
  166.     For i% = 1 To 7
  167.         If MenuFormat(i%).Checked Then
  168.             i% = WritePrivateProfileString("DateTime", "FormatNumber", Str$(i%), INIFILENAME$)
  169.             Exit For
  170.         End If
  171.     Next i%
  172.     ' Make sure the other form is unloaded also:
  173.     End
  174. End Sub
  175. Sub Initialize ()
  176.     ' Set general constants that cannot be declared:
  177.     NL$ = Chr$(13) + Chr$(10)
  178.     TB$ = Chr$(9)
  179. End Sub
  180. Sub MenuAbout_Click ()
  181.     Form_Paint
  182.     MsgBox TB$ + "  DateTime" + NL$ + "            Copyright 
  183.  1991" + NL$ + "    A.C.I. GmbH MicroSysteme" + NL$ + "          Hans-Georg Michna" + NL$ + "74776.2361@compuserve.com" + NL$ + "      Select Help for more info."
  184. End Sub
  185. Sub MenuClick_Click ()
  186.     MenuClick.Checked = Not MenuClick.Checked
  187. End Sub
  188. Sub MenuFormat_Click (Index%)
  189.     If Index% = 7 Then
  190.         ' Make sure that the window is repainted
  191.         ' which may have been obscured by the unfolding menu:
  192.         Refresh
  193.         ' Ask user for its own format string:
  194.         x$ = "Date and time codes:" + NL$
  195.         x$ = x$ + "Day:" + TB$ + "d..dddd" + NL$
  196.         x$ = x$ + "Month:" + TB$ + "m..mmmm" + NL$
  197.         x$ = x$ + "Year:" + TB$ + "yy or yyyy" + NL$
  198.         x$ = x$ + "Full date: ddddd" + NL$
  199.         x$ = x$ + "Hour:" + TB$ + "h or hh" + NL$
  200.         x$ = x$ + "Minute:" + TB$ + "m or mm" + NL$
  201.         x$ = x$ + "Second: s or ss" + NL$
  202.         x$ = x$ + "Full time: ttttt" + NL$
  203.         x$ = x$ + "Date delimiter: /" + NL$
  204.         x$ = x$ + "Example: d/m/yy h:mm"
  205.         y$ = MenuFormat(7).Caption
  206.         x$ = InputBox$(x$, "Enter Your Own Format", MenuFormat(7).Caption)
  207.         If x$ = "" Then
  208.             MenuFormat(7).Caption = y$
  209.             Exit Sub
  210.         Else
  211.             MenuFormat(7).Caption = x$
  212.         End If
  213.         ' Now try if this string really works:
  214.         Err = 0
  215.         On Error Resume Next
  216.         x$ = Format$(Now, MenuFormat(7).Caption)
  217.         ErrNo% = Err
  218.         On Error GoTo 0
  219.         If ErrNo% Then
  220.             MsgBox "Invalid format string:" + NL$ + TB$ + MenuFormat(7).Caption + NL$ + "First format activated instead. Click on Help to get more information.", MB_OK + MB_ICONSTOP, "Format String Error"
  221.             MenuFormat_Click (1)
  222.             Exit Sub
  223.         End If
  224.     End If
  225.     ' Common procedure for all menu items:
  226.     Clear_MenuFormat_Checkmarks
  227.     MenuFormat(Index%).Checked = True
  228.     DTFormat$ = MenuFormat(Index%).Caption
  229. End Sub
  230. Sub MenuHelp_Click ()
  231.     ' The help file path of DATETIME.WRI has been determined in Sub Form_Load
  232.     Err = 0
  233.     On Error Resume Next
  234.     i% = Shell("WRITE.EXE " + HelpFilePath$, SH_NORMAL_FOCUS)
  235.     ErrNo% = Err
  236.     On Error GoTo 0
  237.     If ErrNo% Or i% = 0 Then
  238.          MsgBox "WRITE.EXE not found." + NL$ + "Install Windows properly.", MB_OK + MB_ICONSTOP, "Error"
  239.     End If
  240. End Sub
  241. Sub Zeitmesser_Timer (iZeitmesser%)
  242.     Static ActiveWindow%, SystemFocus%
  243.     If iZeitmesser% = 2 Then
  244.         ' Start timer, runs only for a short time after loading:
  245.         If WindowState = MINIMIZED Then
  246.             ' Just loaded and a short time passed; time to resize
  247.             ' to NORMAL, but then put focus back to where it was
  248.             ' (presumably Program Manager):
  249.             Wnd% = GetActiveWindow()
  250.             WindowState = NORMAL
  251.             Show
  252.             Wnd% = SetFocusAPI(Wnd%)
  253.         End If
  254.         ' The start timer has fulfilled its purpose and will now be disabled for good:
  255.         Unload Zeitmesser(2)
  256.     Else ' iZeitmesser% = 1, i.e. main seconds timer
  257.         If MenuClick.Checked Then Beep
  258.         ' For repaint purposes the string is kept in the global variable DatTim$
  259.         DatTimOld$ = DatTim$
  260.         DatTim$ = Format$(Now, DTFormat$)
  261.         
  262.         ' Check if got system focus:
  263.         i% = GetActiveWindow()
  264.         If i% <> ActiveWindow% Then
  265.             ActiveWindow% = i%
  266.             SystemFocus% = GetWindow(ActiveWindow%, GW_OWNER) = GetWindow(hWnd, GW_OWNER)
  267.         End If
  268.         If Visible Then
  269.             ' In case FullWindow was moved put SmallWindow behind again:
  270.             
  271.             SmallWindow.Left = Left
  272.             SmallWindow.Top = Top
  273.             If SystemFocus% Then ' Still have focus:
  274.                 SmallWindow.Hide
  275.                 If DatTim$ <> DatTimOld$ Then Refresh
  276.             Else ' Focus was lost:
  277.                 ' Replace FullWindow with SmallWindow:
  278.                 Hide
  279.                 SmallWindow.Refresh
  280.             End If
  281.         Else ' Not visible, i.e. borderless SmallWindow is visible
  282.             If SystemFocus% Then
  283.                 SmallWindow.Hide
  284.                 Show
  285.                 Exit Sub
  286.             End If
  287.             If DatTim$ <> DatTimOld$ Then SmallWindow.Refresh
  288.             ' If necessary, bring to top:
  289.             If GetWindow(SmallWindow.hWnd, GW_HWNDFIRST) <> SmallWindow.hWnd Then
  290.                 Const Flags% = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
  291.                 SetWindowPos SmallWindow.hWnd, 0, 0, 0, 0, 0, Flags%
  292.             End If
  293.         End If ' Visible/Not Visible
  294.     End If 'iZeitmesser% = 1
  295. End Sub
  296.