Start your Screen Saver NOW!
Now that Las Vegas Devcon is over, I’ll be posting some of my sample code from the keynote and my session here.
I demonstrated how to make a simple VFP screen saver. To test it, invoking it immediately is useful.
Windows XP allows you to have a screen saver activate after 1 or more minutes of inactivity from the mouse or keyboard.
However, there doesn’t seem to be a simple way to start the screen saver immediately. You can hit the Windowskey + L to lock the computer, but that just brings up the login screen.
You can see which screen saver is registered from the VFP command window:
!start desk.cpl
Here’s some code that will start the current screen saver immediately.
*Start screen saver immediately
#define WM_SYSCOMMAND 0x0112
#define SC_SCREENSAVE 0xF140
DECLARE integer GetDesktopWindow IN WIN32API
DECLARE integer SendMessage IN WIN32API ;
integer hWnd,;
integer msg,;
integer wParam,;
integer lParam
SendMessage(GetDesktopWindow(),WM_SYSCOMMAND,SC_SCREENSAVE,0)
Of course you can make an EXE from this code and put a shortcut on your Start menu and create a Hotkey for it:
*Start screen saver immediately
TEXT TO myvar TEXTMERGE noshow
#define WM_SYSCOMMAND 0x0112
#define SC_SCREENSAVE 0xF140
DECLARE integer GetDesktopWindow IN WIN32API
DECLARE integer SendMessage IN WIN32API ;
integer hWnd,;
integer msg,;
integer wParam,;
integer lParam
SendMessage(GetDesktopWindow(),WM_SYSCOMMAND,SC_SCREENSAVE,0)
ENDTEXT
STRTOFILE(myvar,"SSaver.prg")
STRTOFILE("screen=off","config.fpw")
MODIFY PROJECT SSaver nowait
_vfp.ActiveProject.Files.Add("SSaver.prg")
_vfp.ActiveProject.Files.Add("config.fpw")
_vfp.ActiveProject.Build("ssaver.exe")
_vfp.ActiveProject.Close
*!/n SSaver
*Now create a shortcut to the exe and put it on the start menu
LOCAL oSh as WScript.Shell
oSh=CREATEOBJECT("WScript.Shell")
cStartMenu=oSh.SpecialFolders("StartMenu")
LOCAL oScut as WSCRIPT.WshShortcut
oScut=osh.CreateShortcut(cStartMenu+"\ssaver.lnk")
oScut.Description="VFP Screen saver starter"
oScut.Hotkey="CTRL+ALT+SHIFT+S"
*oScut.IconLocation=
oScut.TargetPath=SYS(5)+CURDIR()+"ssaver.exe"
oScut.Save
You can use the registry or WMI to list the screen savers:
*Use WMI to list screen savers
strComputer = "."
objWMIService = GetObject("winmgmts:\\" + strComputer + "\root\cimv2")
colItems = objWMIService.ExecQuery("Select * from Win32_Desktop")
For Each objItem in colItems
? "Screen Saver Secure: " + TRANSFORM(objItem.ScreenSaverSecure)
??" ",objItem.ScreenSaverExecutable," ",objItem.ScreenSaverTimeout
Next
This code uses SystemParametersInfo to control the screen saver. If your application needs to run for longer than the screen saver timeout and you’d like to have full processing power of the CPU, or if you’d like to show UI without a screen saver showing, you can disable it.
#define SPI_GETSCREENSAVETIMEOUT 0x000E
#define SPI_SETSCREENSAVETIMEOUT 0x000F
#define SPI_GETSCREENSAVEACTIVE 0x0010
#define SPI_SETSCREENSAVEACTIVE 0x0011
#define SPI_GETSCREENSAVERRUNNING 0x0072
#define SPI_SETSCREENSAVERRUNNING 0x0061
#define SPI_SCREENSAVERRUNNING SPI_SETSCREENSAVERRUNNING
#define SPIF_SENDWININICHANGE 0x0002
DECLARE integer SystemParametersInfo IN WIN32API ;
integer uiAction,;
integer uiParam,;
integer @ pvParam ,;
integer fWinini
nval=0
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE,0,@nVal,0)
?"Screen Saver is"+IIF(nval=0," Not","")+" active.",DATETIME()
fEnable =IIF(MESSAGEBOX("Enable screen saver?",4)=6,1,0) && 6=YES
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,fEnable ,0,0)
nval=0
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE,0,@nVal,0)
?"Screen Saver is"+IIF(nval= 0," Not","")+" active.",DATETIME()
ns=SECONDS()
DO WHILE SECONDS()-ns < 60 AND INKEY(1)=0
WAIT WINDOW NOWAIT TRANSFORM(INT(SECONDS()-ns))
ENDDO
39255
Anonymous
August 02, 2005
Sometimes it’s useful to run some code in response to an event like somebody locking or unlocking your...Anonymous
August 13, 2007
The comment has been removedAnonymous
December 31, 2007
PingBack from http://music.247blogging.info/?p=1084Anonymous
June 01, 2009
PingBack from http://woodtvstand.info/story.php?id=11245Anonymous
August 22, 2010
I just discovered that creating a desktop link, using "C:WindowsSystem32scrnsave.scr" as a command, named 'scrnsave.scr', then double-clicking the link, shows the black screen immediately. Moving the mouse or hitting a key on the keyboard will bring back the previous screen. Other .scr executables can be used instead.