by Faisal Arif (6 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)
This lesson will show you how to launch the screensaver with code. It's very simple and only takes a couple of lines of code to accomplish. The first part goes in a module.
(General) (Declarations)
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
Public Const WM_SYSCOMMAND = &H112&
Public Const SC_SCREENSAVE = &HF140&
To actually activate the screensaver only takes one line of code. You can put it anywhere you want, but for my example, I'm placing it in the Click event of a command button.
Command1 Click
Private Sub Command1_Click()
Call SendMessage(Me.hWnd, WM_SYSCOMMAND, SC_SCREENSAVE, _
0&)
End Sub