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.
Declarations #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&
#Else
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
Code
To start the screen saver, use the following code: Dim
result As Long
result = SendMessage(Form1.hWnd, WM_SYSCOMMAND, SC_SCREENSAVE,
0&)
|