Jump to content


Prevent screen saver (windows)


6 replies to this topic

#1 dave_

    Senior Member

  • Members
  • PipPipPipPip
  • 584 posts

Posted 14 January 2007 - 12:45 AM

Anyone got a snippet of code to prevent the screen saver kicking in while an application is running?
I would of thought its an easy piece of code to find but my google skills are off today.

#2 dave_

    Senior Member

  • Members
  • PipPipPipPip
  • 584 posts

Posted 14 January 2007 - 12:54 AM

Ah its ok, found some code here

#3 GameEngine_Designer

    Valued Member

  • Members
  • PipPipPip
  • 100 posts

Posted 14 January 2007 - 02:24 AM

Very good find, I almost started to mak eyou the code in C++. Lol.

#4 TheNut

    Senior Member

  • Moderators
  • 1401 posts
  • LocationThornhill, ON

Posted 14 January 2007 - 04:32 PM

There's an even better way, one that doesn't involve modifying the system parameters.

In your Win32 message loop, look for the message WM_SYSCOMMAND. This will be sent whenever Windows requests to display a screensaver. To prevent windows from starting the screensaver, return 0 to let windows know that you already handled the message (when in fact you didn't).


case WM_SYSCOMMAND:

	if ( wParam == SC_SCREENSAVE )

		return 0;

break;


Simple, clean, and you don't have to worry about resetting the person's system settings once you exit your app.
http://www.nutty.ca - Being a nut has its advantages.

#5 Jare

    Valued Member

  • Members
  • PipPipPip
  • 247 posts

Posted 14 January 2007 - 05:07 PM

You may also want to check wParam for Monitor going low-power:

SC_MONITORPOWER
Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
The lParam parameter can have the following values:
1 - the display is going to low power
2 - the display is being shut off

#6 dave_

    Senior Member

  • Members
  • PipPipPipPip
  • 584 posts

Posted 14 January 2007 - 05:44 PM

Cheers guy's thanks for the advice!

#7 pater

    Valued Member

  • Members
  • PipPipPip
  • 117 posts

Posted 14 January 2007 - 09:03 PM

One aditional thought: Maybe you should not hardcode to disallow any screensaver all the time. While I agree that a screen save during video playback (and often also during games) is anoying and/or may even lead to crashing a directx app sometimes, it may be senseful to allow a screensaver to pop up if your application is minimized or inactive.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users