Shoutbox

Help disabling Windows Screensaver - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Help disabling Windows Screensaver (/showthread.php?tid=36182)

Help disabling Windows Screensaver by Salem on 12-30-2004 at 07:03 PM

Hi There

I'm seriously looking for help on how to disable the windows screensaver whenever the application i created is opened and then have the screensaver enabled again when my application is closed. My program is being written in Visual Basic. I'm fairly new to VB (hav only been programming with it for about a year now) so any help will be appreciated, although the more detailed the help the better (would be better if visual basic code is provided).

For the person who provides the most effective VB code i'd be willing to reward you with a Gmail (1GB) e-mail account, and i'd give you credit in my program (the program will be publically available on the web in 2005). You will also be given beta testing privilages for the product this code will go towards

Thanx in advance

EDIT: Id also like to notify everyone here that I've posted the same request on another forum offering the same reward. Whichever one works first and the best will receive the reward. The winner will be informed by PM.



edited by: RileyM at 10:29 (GMT) on New Years' Eve 2004. Reason for editing: to notify posters that this request was posted at another forum as well


RE: Help disabling Windows Screensaver by Mike on 12-30-2004 at 10:37 PM

Try this :)

Put this on the top of the form code

code:
'<<< CONSTANTS >>>
Private Const SPI_SETSCREENSAVEACTIVE As Long = 17

Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPIF_SENDWININICHANGE = &H2


'<<< DECLARES >>>
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

To enable/disable the screensaver:
code:
   Dim lRet As Long
   
   lRet = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, ByVal 0, SPIF_UPDATEINIFILE)
Change the bolded part to 0 if you want to disable it and to 1 if you want to enable it :)
RE: RE: Help disabling Windows Screensaver by Salem on 12-30-2004 at 10:56 PM

quote:
Originally posted by Mike2
Try this :)

Put this on the top of the form code
code:
'<<< CONSTANTS >>>
Private Const SPI_SETSCREENSAVEACTIVE As Long = 17

Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPIF_SENDWININICHANGE = &H2


'<<< DECLARES >>>
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

To enable/disable the screensaver:
code:
   Dim lRet As Long
   
   lRet = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, ByVal 0, SPIF_UPDATEINIFILE)
Change the bolded part to 0 if you want to disable it and to 1 if you want to enable it :)


i got this error when running the program. sorry for the psot saying i couldnt see bold. when i posted it i saw the bold and then deleted the psot immediately sorry.

RileyM
RE: Help disabling Windows Screensaver by Mike on 12-30-2004 at 10:57 PM

Yeah, you put this code in the form_load event, command1_click event etc :)


RE: RE: Help disabling Windows Screensaver by Salem on 12-30-2004 at 11:01 PM

quote:
Originally posted by Mike2
Yeah, you put this code in the form_load event, command1_click event etc :)


oh, so i must put it on a button, not form load. and the other code also in the button?
RE: Help disabling Windows Screensaver by DJeX on 12-30-2004 at 11:07 PM

Put this code above all other code in the form. (very top)

code:
'<<< CONSTANTS >>>
Private Const SPI_SETSCREENSAVEACTIVE As Long = 17

Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPIF_SENDWININICHANGE = &H2


'<<< DECLARES >>>
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


Now you can put this code in the form_load:

code:
Dim lRet As Long
   
   lRet = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, ByVal 0, SPIF_UPDATEINIFILE)

RE: RE: Help disabling Windows Screensaver by Salem on 12-30-2004 at 11:17 PM

quote:
Originally posted by DJeX
Put this code above all other code in the form. (very top)

code:
'<<< CONSTANTS >>>
Private Const SPI_SETSCREENSAVEACTIVE As Long = 17

Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPIF_SENDWININICHANGE = &H2


'<<< DECLARES >>>
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


Now you can put this code in the form_load:

code:
Dim lRet As Long
   
   lRet = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, ByVal 0, SPIF_UPDATEINIFILE)


sorry if im a bit confused. when u say put it at right at the top of them form do you mean on a button? And put the dim IRet part on form load?

dont i need to put anything in a module?

RileyM
RE: Help disabling Windows Screensaver by DJeX on 12-30-2004 at 11:24 PM

Humm well now that I look at his code I see its a bit dodgy.

I attached a VB project that will enable or disable the screen saver with command buttons.

It can easly be edited to enable or disable on form load.

Give it a try.


RE: RE: Help disabling Windows Screensaver by Salem on 12-30-2004 at 11:53 PM

quote:
Originally posted by DJeX
Humm well now that I look at his code I see its a bit dodgy.

I attached a VB project that will enable or disable the screen saver with command buttons.

It can easly be edited to enable or disable on form load.

Give it a try.


Thanks for that. I've put it in my program and havent received any error messages yet(Y). I'm knackered, so wil test it tomorrow and will get back to you. If everything works i'll PM you to sort out you Gmail invite and how you like to be credited, in my program.

Thnx agen
RileyM:D
RE: RE: Help disabling Windows Screensaver by Salem on 12-31-2004 at 10:16 AM

quote:
Originally posted by DJeX
Humm well now that I look at his code I see its a bit dodgy.

I attached a VB project that will enable or disable the screen saver with command buttons.

It can easly be edited to enable or disable on form load.

Give it a try.


Sorry it did not work.

i created menu a menu where it will allow the user to select whether he/she wants the screensaver disabled.

i've placed the code behind the Enabled button in nthe menu's click event when i want to enable the screensaver and i placed the code behind the disable button on the menu when it should disable the screensaver. unfortunately, both wehn the menu should enable and disable the screensaver the screensaver was displayed anyway.

any ideas?

RileyM
RE: Help disabling Windows Screensaver by Mike on 12-31-2004 at 10:34 AM

Are you sure it doesnt work?
It works on me...
What windows version are you using?

By the way, I attach an example with menus instead of buttons...


RE: RE: Help disabling Windows Screensaver by Salem on 12-31-2004 at 10:37 AM

quote:
Originally posted by Mike2
Are you sure it doesnt work?
It works on me...
What windows version are you using?

By the way, I attach an example with menus instead of buttons...


hi m8. yeh as far as i tried it doesn't work will try the new attachemnt now. Im using Windows XP Home Edition Service Pack 2


Thanx its working congratulations