Advertisement
7_2009-2012 Miscellaneous #225070

Activate the Screensaver

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.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
(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 
Original Comments (3)
Recovered from Wayback Machine