AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

How to Start a Screen Saver using the API

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

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.


#If Win32 Then

    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) _
    As Long 
    Const WM_SYSCOMMAND = &H112&
    Const SC_SCREENSAVE = &HF140&


    Private Declare Function SendMessage Lib "User" _
    (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal _
    wParam As Integer, lParam As Any) As Long

    Const WM_SYSCOMMAND = &H112
    Const SC_SCREENSAVE = &HF140&

#End If       


To start the screen saver, use the following code:

Dim result As Long
result = SendMessage(Form1.hWnd, WM_SYSCOMMAND, SC_SCREENSAVE, 0&)     



Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at