Screen Saver and Windowed Mode
BlitzMax Forums/BlitzMax Programming/Screen Saver and Windowed Mode
| ||
Hello all, I've dug through some old posts looking for a good cross-platform solution to this, but I couldn't find anything. Hopefully, one of you all will know this off the top of your head. How can I go about disabling the screen saver while my game is running, whether in Windowed or Fullscreen mode? In both Windows and Linux, the screensaver goes into action whenever I leave my game sitting at the pause window, and this creates trouble for some users' graphics cards. (I haven't tested on OS X yet, but I don't think this will pose as much of a problem there.) Any advice? Tom |
| ||
I seem to remember some discussion a while back about making BMax itself more resistant to screensavers interrupting it, but I don't recall the details. In any case, I looked around and found a thread on it (by netmaestro & Indiepath) with a solution, resulting in this code (not cross-platform, it's Windows-only, but that's one down and two to go):' Below is from http://www.blitzbasic.com/Community/posts.php?topic=48372 Import "-luser32" Extern "win32" Function SystemParametersInfoW(stuff1:Int,Stuff2:Int,Stuff3:Int,Stuff4:Int) = "SystemParametersInfoW@16" EndExtern Const SPI_SETSCREENSAVEACTIVE :Int = 17 Const SPIF_SENDWININICHANGE :Int = 2 SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, False, Null, SPIF_SENDWININICHANGE) ' saver off Local start = MilliSecs() Graphics 800,600',32,85 '<-uncomment for full screen Repeat Cls DrawText ( MilliSecs() - start ) / 1000, 10,10 Flip ' below reenables it after 70 seconds (with a 1 minute delay, it does kick in at 130 secs) 'If( ( MilliSecs() - start ) / 1000 ) = 70 .. ' SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, True, Null, SPIF_SENDWININICHANGE) ' saver on Until KeyDown(KEY_ESCAPE) SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, True, Null, SPIF_SENDWININICHANGE) ' saver on Rem There's also this, from http://www.devx.com/vb2themax/Tip/19033 which provides additional functionality that could be converted: Private Const SPI_SETSCREENSAVEACTIVE = 17 Private Const SPI_GETSCREENSAVEACTIVE = 16 Private Const SPIF_SENDWININICHANGE = &H2 Private Const SPIF_UPDATEINIFILE = &H1 Private Declare Function SystemParametersInfo Lib "user32" Alias _ "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, _ ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long ' return the Enabled state of the screen saver Function GetScreenSaverState() As Boolean Dim result As Long SystemParametersInfo SPI_GETSCREENSAVEACTIVE, 0, result, 0 GetScreenSaverState = (result <> 0) End Function ' enable or disable the screen saver ' ' if second argument is true, it writes changes in user's profile ' returns True if the operation was successful, False otherwise Function SetScreenSaverState(ByVal enabled As Boolean, _ Optional ByVal PermanentChange As Boolean) As Boolean Dim fuWinIni As Long If PermanentChange Then fuWinIni = SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE End If SetScreenSaverState = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, enabled, _ ByVal 0&, fuWinIni) <> 0 End Function EndRem In my tests (setting my saver to a 1-minute delay), I found that the saver wouldn't a start in fullscreen or windowed while a BlitzMax program was running, even without the "turn off" function above - I think that might be BlitzMax being resistant as I seem to recall reading. Actually, the saver did start in windowed mode (my cursor briefly became an arrow/hourglass at the 1-minute mark), but didn't appear on screen (or interfere with my BlitzMax program's window) until I pressed Escape to end the program, at which point I saw my saver. With the above code, though, that didn't happen. So it seems to disable the saver for real. I added the re-enable call to make sure that the saver would come back up after this program finished, and it did. I also tried out the commented-out test to see if the saver could be re-enabled after 70 seconds, while the program was running and it worked (the hourglass didn't appear at 60 seconds, but did at 130 seconds). |
| ||
Cool--I'd missed that one, somehow. This should probably be sufficient; while things get dog slow under Linux when the screensaver kicks in, it doesn't cause any unexpected graphics failures *knock on wood*. In any case, Windows makes up about 92% of my downloads thus far, with just over 5% for OS X and under 3% for Linux... Thanks! Tom |