VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Activate the Screensaver

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.

Rate Activate the Screensaver


(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 

Download this snippet    Add to My Saved Code

Activate the Screensaver Comments

No comments have been posted about Activate the Screensaver. Why not be the first to post a comment about Activate the Screensaver.

Post your comment

Subject:
Message:
0/1000 characters