home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / redtop / saver.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-11-27  |  6.4 KB  |  198 lines

  1. VERSION 2.00
  2. Begin Form frmSaver 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   0  'None
  5.    ClientHeight    =   2940
  6.    ClientLeft      =   285
  7.    ClientTop       =   3150
  8.    ClientWidth     =   6990
  9.    ControlBox      =   0   'False
  10.    Height          =   3345
  11.    Icon            =   SAVER.FRX:0000
  12.    KeyPreview      =   -1  'True
  13.    Left            =   225
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    MinButton       =   0   'False
  18.    ScaleHeight     =   2940
  19.    ScaleWidth      =   6990
  20.    Top             =   2805
  21.    Width           =   7110
  22.    Begin PictureClip pclRedTop 
  23.       Cols            =   6
  24.       Location        =   "5940,2745,60,960"
  25.       Picture         =   SAVER.FRX:0302
  26.       Rows            =   3
  27.    End
  28.    Begin Image imgRedTop 
  29.       Height          =   855
  30.       Left            =   0
  31.       Top             =   0
  32.       Visible         =   0   'False
  33.       Width           =   915
  34.    End
  35. Option Explicit
  36. Dim FirstTime As Integer
  37. Dim PicIndex As Integer
  38. Dim y1 As Integer
  39. Dim x1 As Integer
  40. Dim incY1 As Integer
  41. Dim incX1 As Integer
  42. Dim picWidth As Integer
  43. Dim picHeight As Integer
  44. Dim LastX As Integer
  45. Dim LastY As Integer
  46. ' Invoked upon an event that could end the screen saver
  47. ' ie. KeyDown, MouseDown, MouseMove
  48. Sub EndScreenSaver ()
  49. Dim i As Integer
  50.     On Error GoTo Fred
  51.     frmSaver.Enabled = False
  52.     Call ShowMouse
  53.     If PWprotected Then
  54.         ' Load up the password form
  55.         ValidPassword = False
  56.         frmEnterPass.Show 1
  57.         ' Decide what to do
  58.         Select Case ValidPassword
  59.             Case 1 ' Valid
  60.                 End
  61.             Case 2 ' Canceled
  62.                 ' Reset this form to be TopMost
  63.                 SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  64.                 ' Set the Form to be System Modal (Ouch!)
  65.                 i = SetSysModalWindow(hWnd)
  66.                 Call HideMouse
  67.                 frmSaver.Enabled = True
  68.                 Exit Sub
  69.             Case 3 ' Invalid
  70.                 frmError.Show 1
  71.                 ' Reset this form to be TopMost
  72.                 SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  73.                 ' Set the Form to be System Modal (Ouch!)
  74.                 i = SetSysModalWindow(hWnd)
  75.                 Call HideMouse
  76.                 frmSaver.Enabled = True
  77.                 Exit Sub
  78.         End Select
  79.     End If
  80.     ' if not password protected then stop the Screen Saver
  81.     End
  82. Fred:
  83.     frmSaver.Enabled = True
  84.     ' Reset this form to be TopMost
  85.     SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  86.     ' Set the Form to be System Modal (Ouch!)
  87.     i = SetSysModalWindow(hWnd)
  88.     Call HideMouse
  89.     Exit Sub
  90. End Sub
  91. Sub Form_Activate ()
  92.     ' The first time the form is activated after it has loaded
  93.     If FirstTime Then
  94.         FirstTime = False
  95.         ' Call the Screen Saver Initialization routine
  96.         Call InitRedTop
  97.         ' Call the Main Screen Saver Loop
  98.         Call RedTop
  99.     End If
  100. End Sub
  101. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  102.     ' If any key is pressed then
  103.     ' Set coords to 0 so as not to catch a
  104.     ' mouse move over the password form
  105.     LastX = 0
  106.     LastY = 0
  107.     EndScreenSaver
  108. End Sub
  109. Sub Form_Load ()
  110. Dim i As Integer
  111.     FirstTime = True
  112.     'Maximize the Window (Which is all black) - It is a screen saver after all!
  113.     WindowState = 2
  114.     ' Set the form to be TopMost
  115.     SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  116.     ' Set the Form to be System Modal (Ouch!)
  117.     i = SetSysModalWindow(hWnd)
  118. End Sub
  119. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  120.     ' If either mouse Button is pressed then
  121.     ' Set coords to 0 so as not to catch a
  122.     ' mouse move over the password form
  123.     LastX = 0
  124.     LastY = 0
  125.     EndScreenSaver
  126. End Sub
  127. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  128.     ' Only Check for mouse move is the user has
  129.     ' asked for this check in the Setup form.
  130.     If MouseMove = 0 Then
  131.         If LastX = 0 Or LastY = 0 Then
  132.             ' first time round or return from EndScreenSaver
  133.             LastX = X
  134.             LastY = Y
  135.         End If
  136.         ' If This position is not near the last position recorded
  137.         If Abs(LastX - X) > 2 * Screen.TwipsPerPixelX Or Abs(LastY - Y) > 2 * Screen.TwipsPerPixelY Then
  138.             ' Set coords to 0 so as not to catch a
  139.             ' mouse move over the password form
  140.             LastX = 0
  141.             LastY = 0
  142.             EndScreenSaver
  143.         Else
  144.             ' Remember the position for the next MouseMove event
  145.             LastX = X
  146.             LastY = Y
  147.         End If
  148.     End If
  149. End Sub
  150. ' Initialize the Screen Saver
  151. Sub InitRedTop ()
  152.         
  153.         ' Set the First Graphic from the PicClip
  154.         PicIndex = 0
  155.         imgRedTop.Picture = pclRedTop.GraphicCell(PicIndex)
  156.         ' Set the width & height of the picture box
  157.         picWidth = 66 * Screen.TwipsPerPixelX
  158.         picHeight = 61 * Screen.TwipsPerPixelY
  159.         ' Set the Start coordinates
  160.         x1 = 0
  161.         y1 = 0
  162.         ' Set the increments in both x and y directions
  163.         incX1 = 25
  164.         incY1 = 20
  165.         ' Make the image visible
  166.         imgRedTop.Visible = True
  167. End Sub
  168. ' The Screen Saver Main Loop
  169. ' This loop only ends on the termination of the Screen Saver
  170. Sub RedTop ()
  171. Dim i As Integer
  172.     While True ' forever!
  173.         ' Get next image from PicClip
  174.         PicIndex = PicIndex + 1
  175.         If PicIndex = 18 Then PicIndex = 0
  176.         imgRedTop.Picture = pclRedTop.GraphicCell(PicIndex)
  177.         ' Get next position
  178.         y1 = y1 + incY1
  179.         x1 = x1 + incX1
  180.         ' Check for edges of screen and if necessary change direction
  181.         If y1 >= Screen.Height - picHeight Or y1 <= 0 Then
  182.             incY1 = -1 * incY1
  183.         End If
  184.         If x1 >= Screen.Width - picWidth Or x1 <= 0 Then
  185.             incX1 = -1 * incX1
  186.         End If
  187.         ' move the image
  188.         imgRedTop.Move x1, y1
  189.         ' Make sure everything is painted properly
  190.         DoEvents
  191.         ' a rather crude way of slowing the display down
  192.         ' without impacting on the system as a whole
  193.         For i = 0 To (500 - SpinSpeed)
  194.             DoEvents
  195.         Next i
  196.     Wend
  197. End Sub
  198.