• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

SystemParametersInfo

I tried to set the screensaver timeout, but it returns 0 to me which means it failed.
dim x&, d&, r&
x& = 2400
r&=SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x&, 0, 0)

The GET one works though
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, d&, 0)
0
fury
Asked:
fury
  • 7
  • 5
1 Solution
 
abelCommented:
You should use the code as follows:
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDCHANGE|SPIF_UPDATEINIFILE)

BTW. The ampersand ("&") is not needed when referring to the prarmeter.

ATOH, I don't know why the function returns zero. Although your code should not work well, the function should return nonzero anyway. If my above mentioned code doesn't work either, please post again with the err.LastDllError number. That should help to cure the problem. And also: is it NT, Win95/98?

Hope this helps,

Regards, Abel
0
 
abelCommented:
Sorry, a little mistake in my code. In stead of "|", use "or". Thus:

SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDCHANGE Or SPIF_UPDATEINIFILE)

I forgot to tell you, using these extra parameters ("SPIF_SENDCHANGE" and "SPIF_UPDATEINIFILE") you notify the system that something changed in the registry and it will be saved to the registry as well. Without these constants, nothing notifyable will happen.
0
 
furyAuthor Commented:
Here is what I did.....
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
    r& = GetLastError()
    MsgBox "Error code is :" & Err.LastDllError
    MsgBox Format(r&)

both msgbox shows 0

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
furyAuthor Commented:
Here is what I did.....
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
    r& = GetLastError()
    MsgBox "Error code is :" & Err.LastDllError
    MsgBox Format(r&)

both msgbox shows 0

Win98

0
 
furyAuthor Commented:
Here is what I did.....
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
    r& = GetLastError()
    MsgBox "Error code is :" & Err.LastDllError
    MsgBox Format(r&)

both msgbox shows 0
Still doesn't work
Win98

0
 
abelCommented:
That's interesting.

Err.LastDllError show zero, meaning "ERROR_SUCCESS" and SystemParametersInfo returns also zero, meaning that there should be an error. Very peculiar.
The code you pasted is also the code you used actually? I mean, with no other dll-call between Err.LastDllError and the call to SystemParametersInfo?

I think it has something to do with Win98. I have seen more "funny" behaviour of Win98 when using common controls or "normal" api-calls. I'll try to find some extra info on this (systemParametersInfo and win98). Maybe I find something out. I'll post again as soon as possible.

Regards, Abel
0
 
abelCommented:
In a fast search through the internet and other resources, I couldn't find a rightfull answer to this strange behaviour to SystemParamersInfo. I don't think Microsoft wants to prohibit the use of setting some parameters in win98, but maybe the constants are changed or so (or a new API should be used). I wasn't able to check MSDN and Tech Net, I didn't get a response from their server. I'll try that tomorrow.

I don't have win98 (yet), so I'm not able to test this particular case for myself. In order to test your code for correctness, you might best try it as well on a Win95/NT machine. On both it should work properly. If it doesn't, something else might be wrong (in stead of using win98).
Something else you can do is spying on windows when the system makes a call to setting the screensavertimeout.

Still, I think this behaviour is very strange: a function reporting something wrong and not setting the error-flag.
Maybe you best reopen this question to other experts - someone else might know a solution and can then answer it instead.

Regards, Abel
0
 
furyAuthor Commented:
I tried on 95..it doesn't work either
0
 
abelCommented:
That's very strange. Could you please make a dummy-project with only the most necessary declarations and code to get this to work and paste is here? I would like to compare your code with mine. I have a fully working app with works on NT4 and Win95 (don't know about 98). If your calls are different or if there's a fault in the declarations, I will probably be able to get it out.

Make sure you paste all the code of a (as small as possible) project.

Regards, Abel
0
 
abelCommented:
Automatically graded?
Did you get it working in the end, Fury? Hope so.

Regards, Abel
0
 
furyAuthor Commented:
oh I  did not get the answer....
'Module

Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_SCREENSAVERRUNNING = 97&
Public Const SPI_SETSCREENSAVETIMEOUT = 15
Public Const SPI_GETSCREENSAVETIMEOUT = 14
Public Const SPIF_SENDWININICHANGE& = &H2
Public Const SPIF_UPDATEINIFILE& = &H1


'Form

Private Sub Command1_Click()
Dim x&
r& = SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, x, 0)
MsgBox "Timeout is " + Format(x)
x& = 2400
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
MsgBox "Set Timeout to: " + Format(x)
r& = SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, x, 0)
MsgBox "Timeout is now: " + Format(x)
End Sub


Thanks for your time :)
0
 
abelCommented:
You're welcome :)
Do you mean that this is working, or is it still not doing anything?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now