VB and VBA Users Source Code: Re: Turn the Screen Saver on or off
[
Home
|
Contents
|
Search
|
Reply
|
Previous
| Next ]
VB/VBA Source Code
Re: Turn the Screen Saver on or off
By:
Ronald Saikali
Email (spam proof):
Email the originator of this post
Date:
Tuesday, July 16, 2002
Hits:
866
Category:
Windows API
Article:
Hi, Turning off the screen saver is not as strait forward as mentionned previously. To stop the screen saver,first you should detect if the screen saver is running then kill the Screen saver window so the function and declaration will be be modified as the following : 'Declarations to add: '******************** Private Const WM_CLOSE = &H10& Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Declare Function SystemParametersInfo Lib "user32" _ Alias "SystemParametersInfoA" _ (ByVal uiAction As Long, _ ByVal uiParam As Long, _ pvParam As Any, _ ByVal fWInIni As Long) As Boolean Private Const SPI_GETSCREENSAVERRUNNING As Long = &H72 'rewritten Function '****************** 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 'activate screen saver Call SendMessage(lHwnd, WM_SYSCOMMAND, SC_SCREENSAVE, 0&) Else 'check if screen saver running Dim bRunning As Boolean SystemParametersInfo SPI_GETSCREENSAVERRUNNING, 0, bRunning, False if bRunning then 'kill the screen saver window Call SendMessage(GetForegroundWindow(), WM_Close, 0&, 0&) end if End If End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder