VB3 Start a Visual Basic Screen Saver Using SendMessage API

Last reviewed: January 9, 1997
Article ID: Q110589
The information in this article applies to:
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SUMMARY

The sample code below shows how to start a Visual Basic screen saver by sending a Windows message to the Control-menu box on the form.

MORE INFORMATION

Microsoft Windows starts screen savers through the System-menu box on a form. The System-menu box is also known as the Control-menu box in Visual Basic. You can send Windows messages to the Control-menu box by using the SendMessage Windows API (application programming interface) function.

Add the following to the general declarations section of Form1, or to a .Bas module file, in Visual Basic:

   ' The following Declare statement must be on one, single line:
   Declare Function SendMessage Lib "User" (ByVal hWnd As Integer,
      ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As
      Long

In the following example, a command button starts the Form1 screen saver:

   Sub Command1_Click ()
      Dim result As Long
      Const WM_SYSCOMMAND = &H112
      Const SC_SCREENSAVE = &HF140
      result = SendMessage(Form1.hWnd, WM_SYSCOMMAND, SC_SCREENSAVE, 0&)
   End Sub

You can find two sample 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.


KBCategory: kbprg kbcode
KBSubcategory: PrgCtrlsStd
Additional reference words: 3.00 .SCR TOPMOST SETWINDOWPOS SCRNSAVE timer


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 9, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.