Page 1 of 1
Resetting System-Idle-Timer to prevent Screensaver
Posted: Wed Apr 30, 2008 3:22 pm
by agent
Hi there.
Does anyone knows how to prevent the sleep mode or screensaver while a program is running?
On MSDN I found this:
http://msdn.microsoft.com/en-us/library ... S.85).aspx .
I thought: Thats it. But it won't work. PB won't accept the API-Command.
Here is my testcode:
Code: Select all
Procedure SK_ResetSystemIdleTimer(status.b = #True)
Protected lReturnCode.l
#ES_SYSTEM_REQUIRED = 1
#ES_DISPLAY_REQUIRED = 2
#ES_AWAYMODE_REQUIRED = 40
#ES_CONTINUOUS = 80000000
lReturnCode = 0
Select status
Case #True
lReturnCode = SetThreadExecutionState_(#ES_SYSTEM_REQUIRED | #ES_DISPLAY_REQUIRED | #ES_CONTINUOUS | #ES_AWAYMODE_REQUIRED)
Case #False
lReturnCode = SetThreadExecutionState_(#ES_CONTINUOUS)
EndSelect
ProcedureReturn lReturnCode
EndProcedure
Posted: Wed Apr 30, 2008 4:10 pm
by Trond
Lookup SystemParametersInfo_() and #SPI_SETSCREENSAVEACTIVE.
Posted: Wed Apr 30, 2008 5:38 pm
by tinman
It is most likely because PB does nto have all the API functions in it's import libraries. There are a few missing, probably because they are limited to newer OSes only.
You could try importing the function from kernel32.lib directly and defining it in your code before calling it, or using LoadLibrary() and finding it by name from there.
However...
MSDN wrote:This function does not stop the screen saver from executing either.
...it wouldn't work for what you want even if you could call it.
Posted: Wed Apr 30, 2008 6:38 pm
by Rook Zimbabwe
Or just turn off screensaver!
Right ckick on the desktop... select PROPERTIES... Click the Screen Saver TAB and turn the dang thing off!

It generally isn't needed these days anyway.
Unless you are trying to circumvent someones away from desktop security...

Posted: Wed Apr 30, 2008 6:49 pm
by agent
Hi at all.
*lol* I really know how to switch my screensaver on and off.
I need this procedure for my backup tool. One of my users got a problem, while a backup is running. If the screensaver turns on (with password activated), the backup stops. After entering the backup will continue. This is terrible, because he backups at night. So the backup will finish next morning
But I have found what I've looked for. Thanx to TROND at this point.
Here are the major functions as procedures if anyone needs:
Code: Select all
Procedure SK_GetScreensaverActive()
Protected bReturnCode.b
bReturnCode = #False
SystemParametersInfo_(#SPI_GETSCREENSAVEACTIVE, #Null, @bReturnCode, #Null)
ProcedureReturn bReturnCode
EndProcedure
Procedure SK_GetScreenSaverRunning()
Protected bReturnCode.b
bReturnCode = #False
SystemParametersInfo_(#SPI_GETSCREENSAVERRUNNING, #Null, @bReturnCode, #Null)
ProcedureReturn bReturnCode
EndProcedure
Procedure SK_GetScreenSaverTimeout()
Protected lReturnCode.l
lReturnCode = #False
SystemParametersInfo_(#SPI_GETSCREENSAVETIMEOUT, #Null, @lReturnCode, #Null)
ProcedureReturn lReturnCode
EndProcedure
Procedure SK_SetScreensaverActive(status.b)
Protected bReturnCode.b
bReturnCode = #False
If status = #True Or status = #False
If SystemParametersInfo_(#SPI_SETSCREENSAVEACTIVE, status.b, #Null, #Null)
bReturnCode = #True
EndIf
EndIf
ProcedureReturn bReturnCode
EndProcedure
Procedure SK_SetScreenSaverTimeout(NewTimeOutInSeconds.l)
Protected bReturnCode.b
bReturnCode = #False
If NewTimeOutInSeconds >= 1
If SystemParametersInfo_(#SPI_SETSCREENSAVETIMEOUT, NewTimeOutInSeconds, #Null, #Null)
bReturnCode = #True
EndIf
EndIf
ProcedureReturn bReturnCode
EndProcedure
Posted: Wed Apr 30, 2008 7:43 pm
by Rook Zimbabwe
Or tell him to turn off screen saver and turn off his monitor... Couple of clicks and one button to push! Better for the monitor as well!
Posted: Wed Apr 30, 2008 8:12 pm
by Mistrel
Why does the backup stop when the screensaver turns on? Isn't this what should be addressed?
Posted: Wed Apr 30, 2008 10:10 pm
by rsts
Mr Rook,
Are you really successful in 'telling' your users what they need to do in order to use your programs?
My users normally tell me what I need to be providing in order for them to consider using it.
cheers
Posted: Thu May 01, 2008 9:23 am
by Foz
Chances are that he *does* switch off his monitor.
The point is that the screen saver will still kick in regardless.