Solved

Screen Saver Programs

Posted on 1998-10-27
5
137 Views
Last Modified: 2010-04-30
I asked a question a week ago and when I asked a follow-up question the expert never got back to me, so here we go again.

I would like to make screensvaer programs in visual basic. Actually I have made the programs. My original question was how do I get windows to recognise it and run it.

The answer that the other expert gave me was that I have to make another program that calls the EXE of the screensaver program and rename it's file extension .scr, I did this by creating the following:

Public Sub Main()
Dim returnvalue As Double
returnvalue = Shell("c:\windows\desktop\screensaver\GMscreensaver.EXE", 3)
AppActivate returnvalue
End
End Sub

I compiled the above and renamed it with the file extension of .scr and then placed it in my windows directory. I then went to windows properties dialogbox and selected this as my screensaver. The program did call the EXE listed in the sub main, but it didn't delay the 5 minutes that I have set in the windows property dialogbox. It just kept calling the program even after I closed it.

So I assume I have some code missing for the .scr program I wrote above. Or there is something else I am supposed to do.
What is the answer?
0
Comment
Question by:timothy1
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
.
0
 
LVL 7

Accepted Solution

by:
kamall earned 50 total points
Comment Utility
How to Create a Screen Saver in Visual Basic

Article ID: Q106239

---------------------------------------------------------------------
The information in this article applies to:

 - Professional, and Enterprise Editions of Microsoft Visual Basic,
   16-bit only, for Windows, version 4.0
 - Professional Edition of Microsoft Visual Basic for Windows,
   versions 2.0 and 3.0
---------------------------------------------------------------------

SUMMARY
=======

You can create a Windows screen saver with Visual Basic by following the

guidelines listed below. However, please note that this article gives only
a very rough outline of what you should do for a robust screen saver. These
are general guidelines only.

MORE INFORMATION
================

Follow these guidelines when creating a Windows screen saver with Visual
Basic:

 - In the File Make EXE File dialog, insert the string SCRNSAVE: (in
   upper case) at the beginning of the Application Title. For example:

   SCRNSAVE:Flying Fish.

 - In the File Make EXE File dialog, specify the program file name
   extension as .SCR instead of .EXE.

 - Locate the .SCR program file in the \WINDOWS directory.

 - Give your form the following property settings so that it
   occupies the entire screen and does not have a title bar:

      Caption     = ""     (no caption)
      ControlBox  = False
      MaxButton   = False
      MinButton   = False
      WindowState = 2      (maximized)

 - Place code in all MouseMove, MouseDown, and KeyDown event handlers

   that exit the program. Because Visual Basic may invoke the MouseMove
   event when the form is first loaded, you must write code to ignore
   the first MouseMove event. The following MouseMove code avoids an
   artifact event that occurs when the application is first activated or
   when the application is running and another instance starts (causing
   loss of focus) and then quits (restoring focus):

   ' VB3Line: Enter the following two lines as one, single line of code:

   Sub Form_MouseMove (Button As Integer, Shift As Integer, _
      X As Single, Y As Single)
      Static count As Integer
      If count > 2 Then
         End
      Else
         count = count + 1
      End If
   End Sub

   This gives you a bit of slack when it comes to artifact MouseMove
   events. You'll want to do something similar with the MouseDown and
   KeyDown events.

Preventing Multiple Launches
----------------------------

Windows usually launches the screen saver program multiple times. To

prevent more than one copy of your screen saver from running, add the
following statements to the Form_Load event handler, or Sub Main if used.

Sub Form_Load ()
   If App.PrevInstance Then
      End
   End If
End Sub

There is no reason to attempt to restore the previous instance of the
screen saver as the active window because it will become the active window
when the new instance ends. All you have to do is terminate when you see
another instance running.


To prevent multiple instances of the application from running as well as to
keep the application running, you should move the code from the Form_Load()
to a Sub Main(). Then set the project's Startup Form Option to Sub Main().

Sub Main ()
   If App.PrevInstance Then   ' If already running, end the application.
      End
   Else
      Form1.Show 1             ' Show the screen saver form.
   End If
End Sub

Launching the Screen Saver
--------------------------

Windows takes care of launching the Screen Saver. It keeps track of system
idle time and launches the screen saver program. You can use a timer
control to periodically draw graphics on the form.

Screen savers are selected and configured from Windows Control Panel in
the Desktop dialog. The screen saver section of this dialog has a button
labeled Setup that invokes the screen saver program with the command
line option /c. When your program is invoked with this option, you can

display a configuration form to allow the user to select settings such
as speed, number of objects, colors, and so on. Detect the /c command line
parameter by checking the Command$ function. For example:

Sub Form_Load ()
   If Command$ = "/c" Then
      frmConfig.Show   ' display configuration form
      Unload Me        ' bypass regular form
   End If
End Sub

When Windows launches the screen saver, it usually specifies the command
line option /s.

Possible Improvements

---------------------

You may also want your program to appear on top of all other windows by
making it a TOPMOST window.

For additional information, please see the following article(s) in the
Microsoft Knowledge Base:

ARTICLE-ID: Q84251
TITLE     : How to Create a Topmost or Floating Window in Visual Basic

Also, you can find two example programs and a complete explanation showing
how to write your own screen savers in Visual Basic in the following book:


   "Visual Basic Workshop 3.0" by John C. Craig, published by Microsoft
   Press.

This article is a rough outline of what you should do for a robust screen
saver. For example, you might want to have the startup be a Sub Main() in
which you check for a previous instance and End if there is one. This would
avoid the form load totally if there were already an instance running. It
might also avoid the artifact MouseMove problem.

Additional reference words: 2.00 3.00 4.00 vb416

KBCategory: kbprg kbcode
KBSubcategory: APrgOther

Copyright (c) Microsoft Corporation. All rights reserved.

Regards

0
 

Author Comment

by:timothy1
Comment Utility
Now that's What I call an ANSWER!
Thks very much!

One follow up question. I use VB5, is that going to be a problem?
0
 
LVL 7

Expert Comment

by:kamall
Comment Utility
I don't think so.
I've just tested several 16-bit screen savers with my Win 95 and they worked just fine.
Good luck with your SCR.
0
 

Author Comment

by:timothy1
Comment Utility
I put the first one I did on my website as freeware

Go to: http://www.gladieux.com/downloads

It's not fancy, but it will do for the first one
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now