Blitz ScreenSaver Help

Blitz3D Forums/Blitz3D Programming/Blitz ScreenSaver Help

Knight #51(Posted 2008) [#1]
Hey guys,

I was wondering if it was possible to make a Blitz3D program to run as a screen saver for your computer.


PowerPC603(Posted 2008) [#2]
It surely is possible.

A screensaver is just any executable, but with the extension .scr instead of .exe.
If you create some exe ("MyScreensaver.exe" for example), just rename it to "MyScreensaver.scr" and put the file in your System32 folder (C:\Windows\System32).
Also, you need to store your media there, if your screensaver needs them (3D-models, sound, ...) or you could program your screensaver to look in a pre-defined directory.

Then set your screensaver to use by Windows (config panel).

See here (C# example) for more info:
http://www.codersource.net/csharp_screen_saver.aspx

Also a Blitz-topic:
http://www.blitzbasic.com/Community/posts.php?topic=39401


Knight #51(Posted 2008) [#3]
Thanks alot PowerPC603!!!!!!!! I'll try it out imediately. :)


Knight #51(Posted 2008) [#4]
It doesn't work. Here is what I did.

1:

Created a .bb file

2:

Programmed it

3:

Made it into an executable

4:

Renamed an executable to an .scr

5:

Put the .scr in C:\WINDOWS\system32

6:

And I don't have any media (just a cube spinning)

Thanks in advance.


Yan(Posted 2008) [#5]
It's not *quite* as simple as that I'm afraid.

Here's a crusty old B2D screensaver example from the dark ages...
;*************************************************
;**** First Attempt At (Crap) Screen Saver
;**** YAN May 2001
;*************************************************
;
;Rename the executable from ????.exe To ????.scr
;
AppTitle "Blitz Screen Saver Config"

in$=Upper(CommandLine$())

Global screenx=640 													;
Global screeny=480													;Probably read these from a config file
Global screendepth=16												;

If Instr(in$,"S") Then StartSaver()									;Test/Preview/Timeout Call

If in$="" Or Instr(in$,"C") Then ConfigSaver(in$)						;Configure/Settings Call

End

Function StartSaver()												;Run the screensaver code
	Graphics screenx,screeny,screendepth
	
	SetBuffer BackBuffer()
	
	FlushKeys
	FlushMouse
	
	x=MouseX()
	y=MouseY()
	
	SeedRnd MilliSecs()  
    Color Rnd(255),Rnd(255),Rnd(255)
	cs=(screenx Shr 5)
	cx=(screenx Shr 1)
	cy=(screeny Shr 1)
	sx=Rnd(1,4):sy=Rnd(1,4)
	Repeat
		Cls
		Oval cx,cy,cs,cs,1
		Flip
		cy=cy+sy:cx=cx+sx
		If cx<=0 Or cx>=(screenx-cs) Then sx=-sx
		If cy<=0 Or cy>=(screeny-cs) Then sy=-sy
	Until GetMouse() Or GetKey() Or y<>MouseY() Or x<>MouseX()
End Function

Function ConfigSaver(cl$)												;Set up saver properties and 
	Graphics 300,300,0,2									;probably save to a config file
	
	SetBuffer FrontBuffer()
	
	Text 0, 0, cl$
	
	Text 100,100,"Configure Me"
		
	Repeat
		If RectsOverlap(120, 210, 60, 30, MouseX(), MouseY(), 1, 1);MouseX()>120 And MouseX()<180 And MouseY()>210 And MouseY()<240
			Color 0,0,200
			Rect 120,210,60,30,1
			Color $ff,$ff,$ff
			Text 133,218,"EXIT"
			If MouseDown(1) Then click=True
		Else
			Color 100,0,200
			Rect 120,210,60,30,1
			Color $ff,$ff,$ff
			Text 133,218,"EXIT"
			click=False
		EndIf
	Until click
End Function

There's a much better example in the code archives (see my profile) but it's written in BMax.


Knight #51(Posted 2008) [#6]
Can you please explain to me what you asking with the command line? How do you configure it too????


Yan(Posted 2008) [#7]
The above code is pretty much self explanatory, so there's little more to add.

Can you please explain to me what you asking with the command line?
The OS passes a command line parameter depending on which mode it wants the screensaver to start in (see code comments).

How do you configure it too????
That's entirely up to your screensaver, if required at all (again, see code comments).


Knight #51(Posted 2008) [#8]
Thanks. But it won't run.


John Blackledge(Posted 2008) [#9]
1. Compile the above code as 'ss.exe'
2. Right click on the exe, select 'Create Shortcut'
3. Right click the shortcut, select 'Properties'.
4. Add <space>/s to the end of the Target line.
5. Save, and run the shortcut.

This is what Windows does when it runs a screensaver - it sends '/s' as the commandline, or '/c' if the user has chosen to config.
Of course for Windows to recongnise and handle it properly it needs to be renamed as ss.scr, and doesn't need the shortcut, that's just for this test.


PowerPC603(Posted 2008) [#10]
Graphics3D 1440, 900, 0, 1

SetBuffer BackBuffer()

cube = CreateCube()
cam = CreateCamera()

PositionEntity cam, 0, 0, -20

While Not KeyHit(1)
	TurnEntity cube, Rnd(0.0, 10.0), Rnd(0.0, 10.0), Rnd(0.0, 10.0)
	RenderWorld
	Flip
Wend

End


This example runs just fine on my machine (laptop with Windows Vista).
Compiled it as "MyScreenSaver.exe", then renamed to "MyScreenSaver.scr" and copied into C:\Windows\System32.

Right click on your desktop, then choose "Edit preferences", "Properties" or something like that (I'm using Dutch version of Windows, so I can't say what you need to choose).
Then choose "ScreenSaver" and select "MyScreenSaver" from the dropdown box.
Press the "Example" button and I see my screensaver running.