'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ' Beginning Beginner Series ' Simple Screen Saver program ' Windows 95/98 Rapid-Q ' Steven Edwards ' April 2000 ' '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ' Windows screen savers are basically an .EXE ' program file that has been renamed with an .SCR ' extention. Actually, there is quite a bit more ' to it, but that is the general idea. ' To make this program act as a screen saver, ' compile it and then rename the .EXE to .SCR ' then either right-click on it to test or copy ' it to the windows\system directory and select ' it in the screen saver setup on the display ' control panel. ' '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ' The program needs to check for the following ' command line arguments at startup: ' ' /c, /c ####, or no arguments at all - ' in response to any of these the saver ' should pop up its configuration dialog. ' ' /s - this indicates that the saver should run ' its screen saver routines. ' ' /p ####, or /l #### - here the saver should ' treat the #### as the decimal representation ' of an HWND, should pop up a child window of ' this HWND, and should run in preview mode ' inside that window. ' ' When parsing command-line options, note that the ' letters may appear as lower-case or upper-case, ' and that there might be either a forward slash or a ' hyphen prefixing the letter, and that there may be ' either a space or a colon after the letter. Thus, ' you should respond to /p #### and -P:#### and all ' options in between. ' ' When running in screen saver mode, the program ' needs to respond to a keypress or mouse movement ' as user request to terminate. '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ' compiler directives $include "rapidq.inc" $typecheck on ' subroutine declarations declare sub ScreenSaver declare sub CheckMouse declare sub ScreenTimer declare sub TerminateSaver declare sub Setup declare sub ExitSetup declare sub Preview(Handle AS INTEGER) ' global variables dim FirstTime as integer dim OldMouseX as integer dim OldMouseY as integer ' form for use as screen saver create frmSaver as qform ' no cursor or border for this form cursor = crNone borderstyle = bsNone ' size of form same as screen width = Screen.Width height = Screen.Height ' set some user action events OnKeyDown = TerminateSaver OnMouseMove = CheckMouse ' set routine for a repaint OnPaint = ScreenSaver ' only object embedded in form create lblSaverMessage as qlabel caption = "Rapid-Q Rules!" end create end create ' make a timer control for the ' screen saver window create SaverTimer as qtimer enabled = false interval = 5000 ontimer = ScreenTimer end create ' form for use with setup command create frmSetup as qform width = 300 height = 150 borderstyle = bsDialog caption = "Rapid-Q Example Screen Saver" create lblMessage as qlabel top = 25 caption = "No setup options at this time." width = 300 alignment = taCenter end create create lblAuthor as qlabel top = 50 caption = "Created by : Steven Edwards" width = 300 alignment = taCenter end create create btnExit as qbutton top = 90 left = 200 caption = "E&xit" onclick = ExitSetup end create center end create '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ' begin subroutines / functions sub ScreenSaver ' code to generate screen saver randomize ' pick a random color scheme select case rnd(3)+1 case 1 frmSaver.color = clRed lblSaverMessage.color = clWhite case 2 frmSaver.color = clBlue lblSaverMessage.color = clRed case 3 frmSaver.color = clPurple lblSaverMessage.color = clWhite end select ' pick a random location for the ' screen saver message near center of ' the screen lblSaverMessage.left = rnd(Screen.Width)/4 + rnd(Screen.Width)/2 lblSaverMessage.top = rnd(Screen.Height)/4 + rnd(screen.Height)/2 ' turn control back over to the timer SaverTimer.enabled = true end sub sub ScreenTimer ' force a repaint of the saver form frmSaver.repaint ' reset timer control SaverTimer.interval = 5000 end sub sub CheckMouse ' check mouse positions for true movement ' without the following code the screensaver ' will terminate almost immediately if FirstTime = 0 then ' we have not gotten a true mouse setting ' so load some initial values OldMouseX = MouseX OldMouseY = MouseY FirstTime = 1 else ' check true mouse setting against new positions if (MouseX <> OldMouseX) or (MouseY <> OLDMOuseY) then ' mouse has actually been moved TerminateSaver end if end if end sub sub TerminateSaver ' exit procedure for screen saver frmSaver.close SaverTimer.enabled = false application.terminate end sub sub Preview(Handle AS integer) ' generate a preview window ' not sure at this point how to accomplish ' this. ' need to poll hwnd passed in command$(2) ' for location/size and place a child ' window in it running the saver demo ' until canceled/setup/closed/etc. end sub sub Setup ' show the setup form frmsetup.showmodal end sub sub ExitSetup ' user clicked Exit button on setup screen frmSetup.close end sub '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ' main program code begins here '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ' determine program action from command line select case ucase$(Command$(1)) case "/S" ' screen saver routines frmSaver.showmodal case "/P" ' run preview mode Preview (Command$(2)) case else ' catchall for "/c", "/C", null, etc. ' run setup routines SetUp end select