January 26, 2021, 05:57:26 AM

Author Topic: [bb] Prevent Windows Screensaver by jfk EO-11110 [ 1+ years ago ]  (Read 584 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Prevent Windows Screensaver
Author : jfk EO-11110
Posted : 1+ years ago

Description : Sometimes you don't want Windows screensavers to become active, like when the window is not restored after the screensaver in some OSes or for some other reason. You don't need to mess with windows Api stuff, there is a much simpler way to do this.

Code :
Code: BlitzBasic
  1. ; prevent windows screensaver
  2.  
  3. ; the following code should be executed in the mainloop, or
  4. ; may be in a function when the variable is global.
  5.  
  6. if millisecs()>prevent_screensaver
  7.  prevent_screensaver=millisecs()+30000
  8.  movemouse mousex(),mousey()
  9. endif


Comments :


plash(Posted 1+ years ago)

 Or just turn it off :D.


jfk EO-11110(Posted 1+ years ago)

 Well I think you should not alter the screensaver settings on the machine of a user of your program... :D


Vic 3 Babes(Posted 1+ years ago)

 I tried this recently, but it didn't work - I'll have to try it again now that I've seen this posting - Windows doesn't detect input from joypads, and the screen saver comes on in the middle of a game - really annoying.I could have sworn it didn't work though.


jfk EO-11110(Posted 1+ years ago)

 joypad? But you still got a mouse, do you? One reason why it probably didn't work is: in this example the mouse is moved to the current mouseposition. So basicly it isn't moved at all. Although, when I wrote this on Win98se, windows thought the mouse was moved noless, because the MoveMouse command was used . Maybe other OSes won't work this way. But I'm positive if you move it eg. by one pixel then it should work in every situation.


Vic 3 Babes(Posted 1+ years ago)

 Sorry - I tried it again - it definitely doesn't work?Yeah - joypad - it's for a Pac Man variant in a window - but the screensaver comes on - I've written a routine to put up an icon to warn the player that the screensaver is due - based on their settings in the settings screen.Works well enough - but Microsoft should have sorted this problem out by now.


grable(Posted 1+ years ago)

 <div class="quote"> Microsoft should have sorted this problem out by now </div>They allready have ;) check here for more options:<a href="http://msdn2.microsoft.com/en-us/library/ms724947.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms724947.aspx[/url]
Code: [Select]
Private
Const SPI_GETSCREENSAVEACTIVE:Int = 16
Const SPI_SETSCREENSAVEACTIVE:Int = 17

Extern "Win32"
Function SystemParametersInfoA:Int( action:Int, param:Int, param2:Byte Ptr, winini:Int)
EndExtern

Global ScreenSaveActive:Int
Public

Function DisableScreenSaver()
' store original setting
SystemParametersInfoA( SPI_GETSCREENSAVEACTIVE, 0, Varptr ScreenSaveActive, 0)
SystemParametersInfoA( SPI_SETSCREENSAVEACTIVE, False, Null, 0)
EndFunction

Function EnableScreenSaver()
' restore original setting
SystemParametersInfoA( SPI_SETSCREENSAVEACTIVE, ScreenSaveActive, Null, 0)
EndFunction



Vic 3 Babes(Posted 1+ years ago)

 Thanks very much for going to the trouble of finding this out.Unfortunately, I'm using B2D and don't recognize some of the commands you've used, and don't really like the idea of disabling someone's screensaver - they may leave their PC whilst the game is still running - in which case the screensaver should be allowed to appear.Besides they haven't really fixed it - they should change the code that resets the screensaver timer to include input from joypads - that would make the most sense.I think they didn't do this because they expect joypad-led games to be run full-screen.Thanks


jfk EO-11110(Posted 1+ years ago)

 About the mouse trick: So you say there's no mouse connected to your machine? This could be a reason why the said mouse trick doesn't work.I think grable meant you could use a winApi function named SystemParametersInfo (part of user32.dll, as far as I see). You have to declare this in a "user32.decls" file in the "userlibs" folder of your blitz installation. As far as I know BLitz2D does support userlibs as well.You may find some help on how to declare windows functions for blitz as userlibs in the blitz3D userlibs forum section.Note Grable's example code may show you how to use it, but actually the code is not Blitz code, so you may have to tweak it a little.


grable(Posted 1+ years ago)

 Its BlitzMax. i keep forgetting that the other blitzes exist  since max is just that good ;)


Vic 3 Babes(Posted 1+ years ago)

 Who said I had no mouse attached?Since I'm using B2D instead of B+, I don't think I can use CallDLL, because there doesn't seem to be any way to pass parameters to the function called - will have a mess with it today though.As for BlitzMax - I think all the Oop stuff is just OTT, and mostly just a way of writing slow code.  I'm sure there are uses for Oop, but I'm also pretty sure that those uses should be a lot rarer than they are - which is why I just upgraded to B+ instead of BMax.If I wanted to go that route, I'd probably code in C++


grable(Posted 1+ years ago)

 <div class="quote"> I think all the Oop stuff is just OTT, and mostly just a way of writing slow code. </div>Who said you HAVE to use OOP? Btw OOP isn't the only thing max brings to the table, its more like a real language. Function pointers/pointers, better arrays, can compile and link with C/C++/ASM (thats what i like the best about it).To each his own i guess =)


jfk EO-11110(Posted 1+ years ago)

 Vic I wasn't talking about CallDLL, but about the userlibs extension of blitz: open your blitz installation folder, when there's a folder named "userlibs" then it should work. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal