?
Solved

SystemParametersInfo

Posted on 1998-07-13
12
Medium Priority
?
489 Views
Last Modified: 2008-03-17
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
Comment
Question by:fury
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 39

Accepted Solution

by:
abel earned 100 total points
ID: 1465548
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
 
LVL 39

Expert Comment

by:abel
ID: 1465549
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
 

Author Comment

by:fury
ID: 1465550
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:fury
ID: 1465551
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
 

Author Comment

by:fury
ID: 1465552
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
 
LVL 39

Expert Comment

by:abel
ID: 1465553
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
 
LVL 39

Expert Comment

by:abel
ID: 1465554
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
 

Author Comment

by:fury
ID: 1465555
I tried on 95..it doesn't work either
0
 
LVL 39

Expert Comment

by:abel
ID: 1465556
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
 
LVL 39

Expert Comment

by:abel
ID: 1465557
Automatically graded?
Did you get it working in the end, Fury? Hope so.

Regards, Abel
0
 

Author Comment

by:fury
ID: 1465558
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
 
LVL 39

Expert Comment

by:abel
ID: 1465559
You're welcome :)
Do you mean that this is working, or is it still not doing anything?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question