Write your own screensaver
This example teaches you how to write a simple screensaver for windows. The screensaver will turn the screen black and balloons will apear and fly to the top.
This is a large example programm. You can download the source code here:
Screen saver source code (32 bit for VB 5.0)
You need two forms and a global module for the screensaver.
The first thing you need is a module with a sub_main procedure:
We need some code that checks, if the screensaver is already running. We need also some code to switch off the mouse cursor. To do so we need a little help from the Windows API:
---code begins here---
Declare Function getmoduleusage Lib "kernel.dll" (ByVal Handle%) As Integer
Declare Function gettaskds Lib "kernel.dll" () As Integer
Declare Sub showcursor Lib "user.dll" (ByVal bshow%)
---code ends here---
The finished sub_main procedure looks like this:
---code begins here---
Rem check of already running
If getmoduleusage(gettaskds()) > 1 Then End
Rem check command string and show configuration dialog
rem if needed
If InStr(Command$, "s") Or InStr(Command$, "S") Then Form1.Show
If InStr(Command$, "c") Or InStr(Command$, "C") Then Form2.Show
---code ends here---
Now open the first form. We need to switch the mouse cursor off, when the screensaver is started, and back on when the user returns to windows.
Add the line " showcursor FALSE " to the form_load procedure,
and add the line " showcursor TRUE " to the form_unload procedure.
That´s it! Now add some picture boxes and moves them in your form, and oh I almost forgot, add the following code to the mouse_move procedure, so that we can quit the screensaver:
---code begins here---
Static mouse As Integer
mouse = mouse + 1
If mouse = 8 Then Unload form1
---code ends here---
The last thing:
When you make an exe-file, change the filename to .SCR instead of .EXE and Change the application title to "SCRNSAVE:(NAME)"
then place the .SCR file in your windows directory and you are done!