Resetting System-Idle-Timer to prevent Screensaver

Just starting out? Need help? Post your questions and find answers here.
agent
New User
New User
Posts: 8
Joined: Fri Dec 03, 2004 1:23 pm
Contact:

Resetting System-Idle-Timer to prevent Screensaver

Post 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
Agent_Sasori
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Lookup SystemParametersInfo_() and #SPI_SETSCREENSAVEACTIVE.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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! :D It generally isn't needed these days anyway.

Unless you are trying to circumvent someones away from desktop security... :wink:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
agent
New User
New User
Posts: 8
Joined: Fri Dec 03, 2004 1:23 pm
Contact:

Post 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
Agent_Sasori
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Why does the backup stop when the screensaver turns on? Isn't this what should be addressed?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post by Foz »

Chances are that he *does* switch off his monitor.

The point is that the screen saver will still kick in regardless.
Post Reply