VB and VBA Users Source Code: Turn the Screen Saver on or off
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Turn the Screen Saver on or off
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, November 06, 2000
Hits:
977
Category:
Windows API
Article:
To switch the screen saver on and off use the following code: Private Const SC_SCREENSAVE = &HF140& Private Const WM_SYSCOMMAND = &H112 Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 'Purpose : Changes the state of the screen saver 'Inputs : bScreenSaver If True, starts the Screen Saver ' else turns the Screen Saver off ' [lHwnd] VB: The form handle OR ' [sFormCaption] VBA: The caption of the form calling the ' routine, can be Me.Caption or Application.Caption 'Outputs : 'Author : Andrew Baker 'Date : 05/11/2000 13:07 'Notes : 'Revisions : Sub ScreenSaver(bScreenSaver As Boolean, Optional lHwnd As Long, Optional sFormCaption As String) Dim lState As Long If lHwnd = 0 Then lHwnd = FindWindowA(vbNullString, sFormCaption) End If If bScreenSaver Then lState = 1 Else lState = -1 End If Call SendMessage(lHwnd, WM_SYSCOMMAND, SC_SCREENSAVE, lState) End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder