How to compile a screensaver *.scr

BlitzPlus Forums/BlitzPlus Programming/How to compile a screensaver *.scr

julianbury(Posted 2003) [#1]
hi, blitzplus guys :-)

I fancy doing a screen saver.
I see that those already installed are scr filetypes.
Do you simply rename an exe file to scr or is there something more to do?
Also, how do you register it with the OS so it is presented as a choice in Display Properites?
And - does the OS kill it directly when something happens or does the saver do the detecting?


sswift(Posted 2003) [#2]
YOu jsut rename the file. When windows tries to display a preview it will call the exe with some command line parameter. And when you click the configure button, it will call another thing. And when you actually run it it calls it with yet another command line parameter. Search the code archives I'm sure there's some code in there that shows what to do.


julianbury(Posted 2003) [#3]
So, just change exe to scr and put it into
C:\Windows\system32\
right?

I'll try that staight away :-)

Thanks


sswift(Posted 2003) [#4]
no, into the windows directory.


julianbury(Posted 2003) [#5]
My OS is Windows XP Home.
I put it in C:\Windows\system32\
because that's where I found the other .scr files.
And it wurkt :-)
But I'll change it to C:\Windows\ if you think it wise.

One remaining problem - I don't know how to discover the parameters with which my program is called.

How do I?

Thanks in anticipation ...


sswift(Posted 2003) [#6]
Ahem...

"Search the code archives I'm sure there's some code in there that shows what to do."

...

http://www.blitzbasic.com/codearcs/codearcs.php?code=266

As for the windows vs windows\system32 dir thing I don't know what to tell you. It could be different in different versions of windows.


JaviCervera(Posted 2003) [#7]
RuntimeError CommandLine$()
This will pop-up a message with the parameters passed to the screensaver.


wedoe(Posted 2003) [#8]
Looks like "kalle" forgot "/p" for preview.


julianbury(Posted 2003) [#9]
Thanks guys ...

RuntimeError CommandLine$() - OK

Ah, I just found Kalles' screen saver.
Thank you, sswift :D
I presume that is where Kalle forget "/p" ?


wedoe(Posted 2003) [#10]
Yep


julianbury(Posted 2003) [#11]
Is "/p" for Preview, then?


Spot-Nothing(Posted 2003) [#12]
i collected some info:

Windows .SCR screen savers
~~~~~~~~~~~~~~~~~~~~~~~~~~

SCR files are nothing more complex than .EXE files with the extension SCR. Windows calls the .SCR file with two command-line options:

/s to launch the screensaver
/c to configure the screensaver

For the windows control panel to recognise the screensaver, the program's module description string must begin with SCRNSAVE: (in uppercase). So, if writing a Visual Basic screensaver, simply set the application title to something like "SCRNSAVE:Test Screensaver". To create a new screen saver simply write a program that checks the command-line option when starting and performs the appropriate action. The display should use a full-screen window (usually with a black background) and should end when any key is pressed or when the mouse is moved. When the program is compiled, rename the .EXE to .SCR and put it into the Windows directory so it can be found by the screensaver selection dialog in Windows.

Edit also parameters setting Web Screen Saver as the default screen saver in [HKEY_CURRENT_USER\Control Panel\Desktop] registry key: ScreenSaveTimeOut Screen Save delay (in seconds). ScreenSaveActive Is screen save mode active? SCRNSAVE.EXE Path of Web Screen Saver (C:\WINDOWS\WEBSS4.SCR).

Deny access to Display Appearance, Background, Screen saver, and Settings pages: Change the values of NoDispAppearancePage,NoDispBackgroundPage,NoDispScrSavPage, and NoDispSettings Page in the key given above.


julianbury(Posted 2003) [#13]
Hi spot_bot :-)

Thanks for the info!

/s to launch the screensaver is a must-have, just so it only executes at the desired moment.
I presume that ignoring /c won't do any harm?

One final question concerning ...
the program's module description string
must begin with SCRNSAVE: (in uppercase).
So, if writing a Visual Basic screensaver,
simply set the application title to something like
"SCRNSAVE:Test Screensaver".


How or where does one put "SCRNSAVE:Test Screensaver" in a BlitzPlus program?

Thank you for your kind attention :-D


Spot-Nothing(Posted 2003) [#14]
> How or where does one put
> "SCRNSAVE:Test Screensaver"
> in a BlitzPlus program?

i don't think it's necessary to do this. just name your project, rename your exe to scr and that's it :-)


wedoe(Posted 2003) [#15]
/s to launch the screensaver
/c to configure the screensaver
/p to preview screensaver


GG


Spot-Nothing(Posted 2003) [#16]
the only question which is still open is how to create a little preview screen or even a little preview animation. i couldn't find any information so far how to do this. anyone else does?


superqix(Posted 2003) [#17]
"/p" also returns the window handle of the little preview window. I think it looks like this "/p:87390"

You would probably need to write a UserLib to draw anything on that window.


Spot-Nothing(Posted 2003) [#18]
a userlib? i see. is there anyone who'd like to code such a screensaver user lib as a paid job? i really can use such a user lib in some commercial projects so i'm willing to pay for someone who can do this. anyone interested?


Warren(Posted 2003) [#19]
The preview window is entirely optional though. Yes, you SHOULD have one, but if you don't it's not a huge problem. I've seen plenty of screensavers that don't do the little preview window at all.


julianbury(Posted 2003) [#20]
I have made a little screensaver for you all to play with.
It does not appear in the mini-window but does respond to the "Preview" button.
The "Settings" button does nothing.
When you have compiled it, rename the .exe to .scr and copy it to the Windows directory.
It should then be immediately available to the "Display Properties -> Screen Saver".
;===============
;   Seti-Bot
;  julianbury
;  2003.08.01
;===============

AppTitle "Seti-bot"
ChangeDir SystemProperty$("appdir")
If CommandLine$() = "/S" Or CommandLine$() = "/s" Then goto startup
End

.startup

Global sincos=9999
Global vertices	= 6000
Global distortion = 1800
Global xaxis, yaxis, zaxis
Global posx, posy, posz
Global xres, yres, xh, yh, yb, yc, xi,yi,di, xm,ym,nn,nnn

Dim icos(sincos+1)
Dim isin(sincos+1)
Dim drawx(vertices)
Dim drawy(vertices)
Dim drawd(vertices)
dim vis(vertices)
Dim drawc(vertices)
Dim viewx(vertices)
Dim viewy(vertices)
Dim viewz(vertices)
Dim worldx(vertices)
Dim worldy(vertices)
Dim worldz(vertices)
dim r(64),g(64),b(64)
dim xc(64), tc(64)
dim xk(64), yk(64), tk(64)
dim xb(8), bar(8)

xres = GadgetWidth(Desktop())
yres = GadgetHeight(Desktop())
xh=xres/2
yh=yres/2

Graphics xres,yres
SetBuffer BackBuffer()
SeedRnd Millisecs()

posx	= 0
posy	= 0
posz	= 0
xaxis	= 0
yaxis	= 0
zaxis	= 0
sincos_tables()

Origin xh, yh
For n=0 To vertices-1
	worldx(n)=Rand(0,2550000)-1270000
	worldy(n)=Rand(0,2550000)-1270000
	worldz(n)=Rand(0,2550000)
Next
for n=0 to 7
	xb(n)=xh-(32+n*6)
	bar(8)=rnd(80)
next
yb=yh-32
for n=0 to 63
	r(n)=rand(1,2)*127
	g(n)=rand(1,2)*127
	b(n)=rand(1,2)*127
	xc(n)=n*4-128
	tc(n)=0
	tk(n)=0
	xk(n)=32+(8*(n mod 4))-xh
	yk(n)=yh-(48+(32*(n/16))+(8*(n/4)))
Next
yc=yh-48


While Not KeyDown(1)
	For n=0 To vertices-1
		worldz(n)=worldz(n)-3000
		If 	worldz(n)<1 Then
			worldx(n)=Rand(0,2550000)-1270000
			worldy(n)=Rand(0,2550000)-1270000
			worldz(n)=2550000
		EndIf
	Next
	rotate_about_object
	drawstars
	if MouseX() <> 0 Or MouseY() <> 0 Or GetKey() <> 0 Or GetMouse() <> 0 then end
Wend


Function sincos_tables()
	s#=360.0/(sincos+1)
	a#=0
	For n=0 To sincos
		isin(n) = (Sin(a#)*4096.0)
		icos(n) = (Cos(a#)*4096.0)
		a#=a#+s#
	Next
End Function


Function rotate_about_object()
	di=0
	nn=0
	For n=0 To vertices-1
		vis(n)=0
		xx# = worldx(n)
		yy# = worldy(n)
		zz# = worldz(n)
		y# = (yy# * icos(xaxis)) - (zz# * isin(xaxis))
		z# = (yy# * isin(xaxis)) + (zz# * icos(xaxis))
		yy#=(y#/4096): zz#=(z#/4096)
		x# = (xx# * icos(yaxis)) + (zz# * isin(yaxis))
		z# = (zz# * icos(yaxis)) - (xx# * isin(yaxis))
		xx#=(x#/4096): zz#=(z#/4096)
		x# = (xx# * icos(zaxis)) - (yy# * isin(zaxis))
		y# = (xx# * isin(zaxis)) + (yy# * icos(zaxis))
		xx#=(x#/4096): yy#=(y#/4096)
		viewx(n) = xx# - posx
		viewy(n) = yy# - posy
		viewz(n) = zz# + posz
		If viewz(n)>0 Then
			drawx(n) = (viewx(n)*distortion)/viewz(n)
			drawy(n) = (viewy(n)*distortion)/viewz(n)
			drawd(n) = 1+((1000*distortion)/viewz(n))
			if drawx(n)>-xh and drawx(n)<xh and drawy(n)>-yh and drawy(n)<yh
				vis(n)=1
				if abs(drawx(n))<200 and abs(drawy(n))<200 then di=drawd(n):nn=n
			endif
		EndIf
	Next
	xi=drawx(nn)
	yi=drawy(nn)
	xm=xi+di/2
	ym=yi+di/2
	if nnn<>nn
		for n=0 to 63:tc(n)=0:next
		for n=0 to 7:bar(n)=1:next
		nnn=nn
	endif
End Function


Function drawstars()
	Cls
	Color 255,255,255
	For n=0 To vertices-1
		if vis(n)=1 then Rect drawx(n), drawy(n),drawd(n),drawd(n)
	Next
	Color 0,255,0
	line xm,ym+8,xm-4,ym+32
	line xm,ym+8,xm+4,ym+32
	line xm,ym-8,xm-4,ym-32
	line xm,ym-8,xm+4,ym-32
	line xm+8,ym,xm+32,ym-4
	line xm+8,ym,xm+32,ym+4
	line xm-8,ym,xm-32,ym-4
	line xm-8,ym,xm-32,ym+4
	for n=0 to 63
		rr=rnd(64)
		if rr<n
		  rr=rnd(40)
			if rr=3 then tc(n)=rnd(0,1)
		endif
	Next
	Color 255,0,0
	for n=0 to 63
		if tc(n)=1 then rect xc(n),yc,3,16
	next
	if rnd(12)=7
		n=rnd(0,63)
		r(n)=rnd(0,1)*255
		g(n)=rnd(0,1)*255
		b(n)=rnd(0,1)*255
	endif
	for n=0 to 63
		rr=rnd(32)
		if rr=1 then tk(n)=rnd(0,1)
		if tk(n)=1 then Color r(n),g(n),b(n):rect xk(n),yk(n),6,6
	next
	for n=0 to 7
		bar(n)=bar(n)+rnd(0,16)-8
		if bar(n)<1 then bar(n)=1
		Color r(n),g(n),b(n):rect xb(n),yb-bar(n),4,bar(n)
	next
	Flip
End Function


Well there it is :-)


SuperDan(Posted 2003) [#21]
What about installing the screensaver?
Does anyone know how to edit the registry from Blitz+ to make the screensaver the Windows default?
eg. If you had an installer program as a front end.


Spot-Nothing(Posted 2003) [#22]
yeah. check for HKEY_CURRENT_USER\Control Panel\Desktop ... there you have some screensaver flags and also a key with the path to the default screensaver.


Difference(Posted 2003) [#23]
This used to work:
(Powerbasic code)
Sub SelectAsDefault( longsavername As Asciiz*%Max_Path  )
    Local shortname As Asciiz*%Max_Path '(260 chars)
    Local ret As Long
    shortname=Space$(%Max_Path)
    ret=GetShortPathName (longsavername,shortname,%Max_Path)
    WritePrivateProfileString "boot","SCRNSAVE.EXE",shortname,"system.ini"
    SystemParametersInfo %SPI_SETSCREENSAVEACTIVE,%TRUE,%Null,%TRUE
    ' that sends a WM_WININICHANGE so that DisplayProperties dialog  ' knows we've changed
End Sub


It's called with the full path of the screensaver exe


Nathan(Posted 2003) [#24]
Hey Julian,

great little screensaver you made. I had fun with it.


julianbury(Posted 2003) [#25]
Hi, Nathan

If you made fun changes, post 'em here so I can play with them too :-)