Location Earth, (I Think)
Home
About Us
Contact Us
Links
Creating A Screen Saver
A DarkBasic Step By Step Guide.
 
If you want to make a ScreenSaver in DarkBasic, Then Copy the code from the Panel Below and Place it in a DarkBasic Window, Change the settings so Instead of making a ".EXE", it will create a ".Scr", Then add the ScreenSaver in the RunScreenSaver() Function, Place your settings window in the ChangeSetting() Function, Personally id use BlueGui to make a Setting Window, But you could use a free alternative like WinGui.
 
For changing the Properties, I usually store the Required information in the registry, you can access this from DarkBasic Automatically and it means you dont have to mess around with Files, I would suggest using a System like BlueGui or WinGui for creating your Setting Window, Althought if your ScreenSaver has no properties, then you may wish to use a popup, such as MsgBox("Screen Saver Properties","This Screen Saver has no changable properties",MsgOK).
 
In the empty Template Below, you will Notice that "/P" Has been Remmed Out, This is for the little Preview window you get on the Screen Saver Tab in Display properties, once you have completed your ScreenSaver, If you want to know if it is compatable then UnRem That Line, Recompile, and Reintall the Screen Saver.
 
How to install these ScreenSavers?
If you followed the instructions Above then when compiled, DarkBasic should make a file with the Extension ".Scr", Right Click on the File Icon, and Select "Install", If you had already installed a ScreenSaver with the Same Name, Then it will Automatically Remove the old version, and install the new version of your ScreenSaver, This is handy as you can test it throughout Development.
 
Copy and Paste This Code, (Remember to change the Executable to ".Scr")
 

` ------------------------------------------------------------------------------------------------------

  GLOBAL Cmd$ AS STRING

         Cmd$ = UPPER$(LEFT$(CL$(),2))
      IF Cmd$ = ""   THEN cmd$ = "/S"
      IF Cmd$ = "/C" THEN ChangeSettings()
      IF Cmd$ = "/S" THEN RunScreenSaver()
    ` IF Cmd$ = "/P" Then RunScreenSaver()

         End : ` Else Invalid Option

` ------------------------------------------------------------------------------------------------------

 

 

`        -----------------------------------------------------------------------------------------------

FUNCTION RunScreenSaver()

      If Cmd$ = "/P" : PreviewScreenSaver()

         Else Hide Mouse

         EndIf

 

Do

 

` Add Your Code Here


If Cmd$ <> "/P"
If MouseMoveX() <> 0 Then End
If MouseMoveY
() <> 0 Then End
If MouseClick
() <> 0 Then End
If   ScanCode
() <> 0 Then End
EndIf
: Loop

ENDFUNCTION

FUNCTION ChangeSettings()

 

` Add Your Code Here

 

ENDFUNCTION

`        -----------------------------------------------------------------------------------------------

Function PreviewScreenSaver()
       ` Thanks To JessT and IanM for This Function

         Local user32 As Integer
         Local
Hwnd   As DWord
         Local
temp   As DWord

         Local x      As Integer
         Local
y      As Integer
         Local
memnum
As Integer

         Set Window On
         Set Window Layout
0,0,0
         user32 = 1
         memnum = 1

         parent = Val(Right$(CL$(),Len(CL$())-3))
         Load DLL "user32.dll",1
         Hwnd = Call DLL(1,"GetActiveWindow")
         temp = Call DLL(1,"SetParent",Hwnd,parent)
         Make Memblock memnum,20
         Call Dll user32,"GetWindowRect",parent,Get Memblock Ptr(memnum)
         x = MemBlock DWord(memnum,0)
         y = MemBlock DWord(memnum,4)
         Set Display Mode 153,113,32
         Call DLL user32,"MoveWindow",x,y,153,113,1

EndFunction

`        -----------------------------------------------------------------------------------------------